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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define INCL_DOSERRORS
18 #include "apr_arch_file_io.h"
19 #include "apr_file_io.h"
20 #include "apr_general.h"
22 #include "apr_strings.h"
23 #include "apr_portable.h"
27 APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *pool)
34 sprintf(pipename, "/pipe/%d.%d", getpid(), id++);
35 rc = DosCreateNPipe(pipename, filedes, NP_ACCESS_INBOUND, NP_NOWAIT|1, 4096, 4096, 0);
38 return APR_FROM_OS_ERROR(rc);
40 rc = DosConnectNPipe(filedes[0]);
42 if (rc && rc != ERROR_PIPE_NOT_CONNECTED) {
44 return APR_FROM_OS_ERROR(rc);
47 rc = DosOpen (pipename, filedes+1, &action, 0, FILE_NORMAL,
48 OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
49 OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYREADWRITE,
54 return APR_FROM_OS_ERROR(rc);
57 (*in) = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t));
58 rc = DosCreateEventSem(NULL, &(*in)->pipeSem, DC_SEM_SHARED, FALSE);
63 return APR_FROM_OS_ERROR(rc);
66 rc = DosSetNPipeSem(filedes[0], (HSEM)(*in)->pipeSem, 1);
69 rc = DosSetNPHState(filedes[0], NP_WAIT);
75 DosCloseEventSem((*in)->pipeSem);
76 return APR_FROM_OS_ERROR(rc);
80 (*in)->filedes = filedes[0];
81 (*in)->fname = apr_pstrdup(pool, pipename);
83 (*in)->buffered = FALSE;
87 (*in)->blocking = BLK_ON;
88 apr_pool_cleanup_register(pool, *in, apr_file_cleanup, apr_pool_cleanup_null);
90 (*out) = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t));
92 (*out)->filedes = filedes[1];
93 (*out)->fname = apr_pstrdup(pool, pipename);
94 (*out)->isopen = TRUE;
95 (*out)->buffered = FALSE;
99 (*out)->blocking = BLK_ON;
100 apr_pool_cleanup_register(pool, *out, apr_file_cleanup, apr_pool_cleanup_null);
107 APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename, apr_fileperms_t perm, apr_pool_t *pool)
109 /* Not yet implemented, interface not suitable */
115 APR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe, apr_interval_time_t timeout)
117 if (thepipe->pipe == 1) {
118 thepipe->timeout = timeout;
120 if (thepipe->timeout >= 0) {
121 if (thepipe->blocking != BLK_OFF) {
122 thepipe->blocking = BLK_OFF;
123 return APR_FROM_OS_ERROR(DosSetNPHState(thepipe->filedes, NP_NOWAIT));
126 else if (thepipe->timeout == -1) {
127 if (thepipe->blocking != BLK_ON) {
128 thepipe->blocking = BLK_ON;
129 return APR_FROM_OS_ERROR(DosSetNPHState(thepipe->filedes, NP_WAIT));
138 APR_DECLARE(apr_status_t) apr_file_pipe_timeout_get(apr_file_t *thepipe, apr_interval_time_t *timeout)
140 if (thepipe->pipe == 1) {
141 *timeout = thepipe->timeout;
149 APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
150 apr_os_file_t *thefile,
151 int register_cleanup,
154 (*file) = apr_pcalloc(pool, sizeof(apr_file_t));
155 (*file)->pool = pool;
156 (*file)->isopen = TRUE;
158 (*file)->blocking = BLK_UNKNOWN; /* app needs to make a timeout call */
159 (*file)->timeout = -1;
160 (*file)->filedes = *thefile;
162 if (register_cleanup) {
163 apr_pool_cleanup_register(pool, *file, apr_file_cleanup,
164 apr_pool_cleanup_null);
172 APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file,
173 apr_os_file_t *thefile,
176 return apr_os_pipe_put_ex(file, thefile, 0, pool);