Apache HTTPD
pipe.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdio.h>
18#include <nks/fsio.h>
19#include <nks/errno.h>
20
21#include "apr_arch_file_io.h"
22#include "apr_strings.h"
23#include "apr_portable.h"
24#include "apr_arch_inherit.h"
25
27{
28#ifdef USE_FLAGS
29 unsigned long flags;
30
31 if (fcntl(thepipe->filedes, F_GETFL, &flags) != -1)
32 {
33 flags &= ~FNDELAY;
34 fcntl(thepipe->filedes, F_SETFL, flags);
35 }
36#else
37 errno = 0;
38 fcntl(thepipe->filedes, F_SETFL, 0);
39#endif
40
41 if (errno)
42 return errno;
43
44 thepipe->blocking = BLK_ON;
45 return APR_SUCCESS;
46}
47
49{
50#ifdef USE_FLAGS
51 unsigned long flags;
52
53 errno = 0;
54 if (fcntl(thepipe->filedes, F_GETFL, &flags) != -1)
55 {
56 flags |= FNDELAY;
57 fcntl(thepipe->filedes, F_SETFL, flags);
58 }
59#else
60 errno = 0;
61 fcntl(thepipe->filedes, F_SETFL, FNDELAY);
62#endif
63
64 if (errno)
65 return errno;
66
67 thepipe->blocking = BLK_OFF;
68 return APR_SUCCESS;
69}
70
72{
73 if (thepipe->is_pipe == 1) {
74 thepipe->timeout = timeout;
75 if (timeout >= 0) {
76 if (thepipe->blocking != BLK_OFF) { /* blocking or unknown state */
77 return pipenonblock(thepipe);
78 }
79 }
80 else {
81 if (thepipe->blocking != BLK_ON) { /* non-blocking or unknown state */
82 return pipeblock(thepipe);
83 }
84 }
85 return APR_SUCCESS;
86 }
87 return APR_EINVAL;
88}
89
91{
92 if (thepipe->is_pipe == 1) {
93 *timeout = thepipe->timeout;
94 return APR_SUCCESS;
95 }
96 return APR_EINVAL;
97}
98
103{
104 int *dafile = thefile;
105
106 (*file) = apr_pcalloc(pool, sizeof(apr_file_t));
107 (*file)->pool = pool;
108 (*file)->eof_hit = 0;
109 (*file)->is_pipe = 1;
110 (*file)->blocking = BLK_UNKNOWN; /* app needs to make a timeout call */
111 (*file)->timeout = -1;
112 (*file)->ungetchar = -1; /* no char avail */
113 (*file)->filedes = *dafile;
114 if (!register_cleanup) {
115 (*file)->flags = APR_FOPEN_NOCLEANUP;
116 }
117 (*file)->buffered = 0;
118#if APR_HAS_THREADS
119 (*file)->thlock = NULL;
120#endif
121 if (register_cleanup) {
122 apr_pool_cleanup_register((*file)->pool, (void *)(*file),
125 }
126 return APR_SUCCESS;
127}
128
132{
133 return apr_os_pipe_put_ex(file, thefile, 0, pool);
134}
135
138{
139 int filedes[2];
140
141 if (pipe(filedes) == -1) {
142 return errno;
143 }
144
145 (*in) = (apr_file_t *)apr_pcalloc(pool_in, sizeof(apr_file_t));
146 (*out) = (apr_file_t *)apr_pcalloc(pool_out, sizeof(apr_file_t));
147
148 (*in)->pool = pool_in;
149 (*out)->pool = pool_out;
150 (*in)->filedes = filedes[0];
151 (*out)->filedes = filedes[1];
152 (*in)->flags = APR_INHERIT;
153 (*out)->flags = APR_INHERIT;
154 (*in)->is_pipe =
155 (*out)->is_pipe = 1;
156 (*out)->fname =
157 (*in)->fname = NULL;
158 (*in)->buffered =
159 (*out)->buffered = 0;
160 (*in)->blocking =
161 (*out)->blocking = BLK_ON;
162 (*in)->timeout =
163 (*out)->timeout = -1;
164 (*in)->ungetchar = -1;
165 (*in)->thlock =
166 (*out)->thlock = NULL;
167 (void) apr_pollset_create(&(*in)->pollset, 1, pool_in, 0);
168 (void) apr_pollset_create(&(*out)->pollset, 1, pool_out, 0);
169
170 apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup,
172 apr_pool_cleanup_register((*out)->pool, (void *)(*out), apr_unix_file_cleanup,
174
175 return APR_SUCCESS;
176}
177
180{
181 switch (blocking) {
182 case APR_FULL_BLOCK:
183 break;
184 case APR_READ_BLOCK:
186 break;
187 case APR_WRITE_BLOCK:
189 break;
190 default:
193 break;
194 }
195}
196
198{
199 return file_pipe_create(in, out, pool, pool);
200}
201
203 apr_file_t **out,
206{
208
210 return status;
211 }
212
214
215 return APR_SUCCESS;
216}
217
220{
222
224 return status;
225 }
226
228
229 return APR_SUCCESS;
230}
231
234{
235 return APR_ENOTIMPL;
236}
237
238
239
APR Portability Routines.
APR Strings library.
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_EINVAL
Definition apr_errno.h:711
const char apr_ssize_t int flags
Definition apr_encode.h:168
const void apr_status_t(*) apr_status_t(* APR_DECLARE)(void) apr_pool_pre_cleanup_register(apr_pool_t *p
Definition apr_pools.h:646
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_int32_t apr_fileperms_t
apr_file_t * thefile
apr_file_t apr_int32_t apr_pool_t apr_pool_t * pool_out
const char apr_file_t * file
apr_file_t apr_int32_t blocking
const char apr_int32_t apr_fileperms_t perm
apr_file_t apr_int32_t apr_pool_t * pool_in
#define APR_FOPEN_NOCLEANUP
Definition apr_file_io.h:74
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
int apr_os_file_t
apr_os_file_t int register_cleanup
apr_size_t const char * filename
Definition apr_shm.h:72
apr_int32_t in
#define APR_WRITE_BLOCK
#define APR_FULL_BLOCK
int int status
#define APR_READ_BLOCK
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
static apr_file_t * out
Definition mod_info.c:85
return NULL
Definition mod_so.c:359
static apr_status_t pipenonblock(apr_file_t *thepipe)
Definition pipe.c:48
static apr_status_t file_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *pool_in, apr_pool_t *pool_out)
Definition pipe.c:136
static apr_status_t pipeblock(apr_file_t *thepipe)
Definition pipe.c:26
static void file_pipe_block(apr_file_t **in, apr_file_t **out, apr_int32_t blocking)
Definition pipe.c:178
#define APR_INHERIT
apr_pool_t * pool
apr_status_t apr_unix_file_cleanup(void *thefile)
Definition open.c:71
#define filedes
IN ULONG IN INT timeout