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#define INCL_DOSERRORS
18#include "apr_arch_file_io.h"
19#include "apr_file_io.h"
20#include "apr_general.h"
21#include "apr_lib.h"
22#include "apr_strings.h"
23#include "apr_portable.h"
24#include <string.h>
25#include <process.h>
26
29{
30 ULONG filedes[2];
31 ULONG rc, action;
32 static int id = 0;
33 char pipename[50];
34
35 sprintf(pipename, "/pipe/%d.%d", getpid(), id++);
37
38 if (rc)
39 return APR_FROM_OS_ERROR(rc);
40
42
43 if (rc && rc != ERROR_PIPE_NOT_CONNECTED) {
44 DosClose(filedes[0]);
45 return APR_FROM_OS_ERROR(rc);
46 }
47
48 rc = DosOpen (pipename, filedes+1, &action, 0, FILE_NORMAL,
51 NULL);
52
53 if (rc) {
54 DosClose(filedes[0]);
55 return APR_FROM_OS_ERROR(rc);
56 }
57
58 (*in) = (apr_file_t *)apr_palloc(pool_in, sizeof(apr_file_t));
59 rc = DosCreateEventSem(NULL, &(*in)->pipeSem, DC_SEM_SHARED, FALSE);
60
61 if (rc) {
62 DosClose(filedes[0]);
63 DosClose(filedes[1]);
64 return APR_FROM_OS_ERROR(rc);
65 }
66
67 rc = DosSetNPipeSem(filedes[0], (HSEM)(*in)->pipeSem, 1);
68
69 if (!rc) {
71 }
72
73 if (rc) {
74 DosClose(filedes[0]);
75 DosClose(filedes[1]);
76 DosCloseEventSem((*in)->pipeSem);
77 return APR_FROM_OS_ERROR(rc);
78 }
79
80 (*in)->pool = pool_in;
81 (*in)->filedes = filedes[0];
82 (*in)->fname = apr_pstrdup(pool_in, pipename);
83 (*in)->isopen = TRUE;
84 (*in)->buffered = FALSE;
85 (*in)->flags = 0;
86 (*in)->pipe = 1;
87 (*in)->timeout = -1;
88 (*in)->blocking = BLK_ON;
91
92 (*out) = (apr_file_t *)apr_palloc(pool_out, sizeof(apr_file_t));
93 (*out)->pool = pool_out;
94 (*out)->filedes = filedes[1];
95 (*out)->fname = apr_pstrdup(pool_out, pipename);
96 (*out)->isopen = TRUE;
97 (*out)->buffered = FALSE;
98 (*out)->flags = 0;
99 (*out)->pipe = 1;
100 (*out)->timeout = -1;
101 (*out)->blocking = BLK_ON;
104
105 return APR_SUCCESS;
106}
107
110{
111 switch (blocking) {
112 case APR_FULL_BLOCK:
113 break;
114 case APR_READ_BLOCK:
116 break;
117 case APR_WRITE_BLOCK:
119 break;
120 default:
123 break;
124 }
125}
126
133
135 apr_file_t **out,
138{
140
142 return status;
143
145
146 return APR_SUCCESS;
147}
148
150 apr_file_t **out,
154{
156
158 return status;
159
161
162 return APR_SUCCESS;
163}
164
165
167{
168 /* Not yet implemented, interface not suitable */
169 return APR_ENOTIMPL;
170}
171
172
173
175{
176 if (thepipe->pipe == 1) {
177 thepipe->timeout = timeout;
178
179 if (thepipe->timeout >= 0) {
180 if (thepipe->blocking != BLK_OFF) {
181 thepipe->blocking = BLK_OFF;
183 }
184 }
185 else if (thepipe->timeout == -1) {
186 if (thepipe->blocking != BLK_ON) {
187 thepipe->blocking = BLK_ON;
189 }
190 }
191 }
192 return APR_EINVAL;
193}
194
195
196
198{
199 if (thepipe->pipe == 1) {
200 *timeout = thepipe->timeout;
201 return APR_SUCCESS;
202 }
203 return APR_EINVAL;
204}
205
206
207
212{
213 (*file) = apr_pcalloc(pool, sizeof(apr_file_t));
214 (*file)->pool = pool;
215 (*file)->isopen = TRUE;
216 (*file)->pipe = 1;
217 (*file)->blocking = BLK_UNKNOWN; /* app needs to make a timeout call */
218 (*file)->timeout = -1;
219 (*file)->filedes = *thefile;
220
221 if (register_cleanup) {
224 }
225
226 return APR_SUCCESS;
227}
228
229
230
234{
235 return apr_os_pipe_put_ex(file, thefile, 0, pool);
236}
#define TRUE
Definition abts.h:38
#define FALSE
Definition abts.h:35
APR File I/O Handling.
APR Miscellaneous library routines.
APR general purpose library routines.
APR Portability Routines.
APR Strings library.
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_EINVAL
Definition apr_errno.h:711
apr_redis_t * rc
Definition apr_redis.h:173
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_FROM_OS_ERROR(e)
Definition apr_errno.h:1214
#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_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 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 void file_pipe_block(apr_file_t **in, apr_file_t **out, apr_int32_t blocking)
Definition pipe.c:178
apr_status_t apr_file_cleanup(void *thefile)
Definition open.c:25
#define filedes
IN ULONG IN INT timeout