upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / file_io / netware / pipe.c
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
26 static apr_status_t pipeblock(apr_file_t *thepipe)
27 {
28 #ifdef USE_FLAGS
29     int                         err;
30         unsigned long   flags;
31
32         if (fcntl(thepipe->filedes, F_GETFL, &flags) != -1)
33         {
34                 flags &= ~FNDELAY;
35                 fcntl(thepipe->filedes, F_SETFL, flags);
36         }
37 #else
38         errno = 0;
39                 fcntl(thepipe->filedes, F_SETFL, 0);
40 #endif
41
42     if (errno)
43         return errno;
44
45     thepipe->blocking = BLK_ON;
46     return APR_SUCCESS;
47 }
48
49 static apr_status_t pipenonblock(apr_file_t *thepipe)
50 {
51 #ifdef USE_FLAGS
52         int                             err;
53         unsigned long   flags;
54
55     errno = 0;
56         if (fcntl(thepipe->filedes, F_GETFL, &flags) != -1)
57         {
58                 flags |= FNDELAY;
59                 fcntl(thepipe->filedes, F_SETFL, flags);
60         }
61 #else
62         errno = 0;
63                 fcntl(thepipe->filedes, F_SETFL, FNDELAY);
64 #endif
65
66     if (errno)
67         return errno;
68
69     thepipe->blocking = BLK_OFF;
70     return APR_SUCCESS;
71 }
72
73 APR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe, apr_interval_time_t timeout)
74 {
75     if (thepipe->is_pipe == 1) {
76         thepipe->timeout = timeout;
77         if (timeout >= 0) {
78             if (thepipe->blocking != BLK_OFF) { /* blocking or unknown state */
79                 return pipenonblock(thepipe);
80             }
81         }
82         else {
83             if (thepipe->blocking != BLK_ON) { /* non-blocking or unknown state */
84                 return pipeblock(thepipe);
85             }
86         }
87         return APR_SUCCESS;
88     }
89     return APR_EINVAL;
90 }
91
92 APR_DECLARE(apr_status_t) apr_file_pipe_timeout_get(apr_file_t *thepipe, apr_interval_time_t *timeout)
93 {
94     if (thepipe->is_pipe == 1) {
95         *timeout = thepipe->timeout;
96         return APR_SUCCESS;
97     }
98     return APR_EINVAL;
99 }
100
101 APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file,
102                                              apr_os_file_t *thefile,
103                                              int register_cleanup,
104                                              apr_pool_t *pool)
105 {
106     int *dafile = thefile;
107     
108     (*file) = apr_pcalloc(pool, sizeof(apr_file_t));
109     (*file)->pool = pool;
110     (*file)->eof_hit = 0;
111     (*file)->is_pipe = 1;
112     (*file)->blocking = BLK_UNKNOWN; /* app needs to make a timeout call */
113     (*file)->timeout = -1;
114     (*file)->ungetchar = -1; /* no char avail */
115     (*file)->filedes = *dafile;
116     if (!register_cleanup) {
117         (*file)->flags = APR_FILE_NOCLEANUP;
118     }
119     (*file)->buffered = 0;
120 #if APR_HAS_THREADS
121     (*file)->thlock = NULL;
122 #endif
123     if (register_cleanup) {
124         apr_pool_cleanup_register((*file)->pool, (void *)(*file),
125                                   apr_unix_file_cleanup,
126                                   apr_pool_cleanup_null);
127     }
128     return APR_SUCCESS;
129 }
130
131 APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file,
132                                           apr_os_file_t *thefile,
133                                           apr_pool_t *pool)
134 {
135     return apr_os_pipe_put_ex(file, thefile, 0, pool);
136 }
137
138 APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *pool)
139 {
140         int             filedes[2];
141         int             err;
142
143     if (pipe(filedes) == -1) {
144         return errno;
145     }
146
147     (*in) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
148     (*out) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
149
150     (*in)->pool     =
151     (*out)->pool    = pool;
152     (*in)->filedes   = filedes[0];
153     (*out)->filedes  = filedes[1];
154     (*in)->flags     = APR_INHERIT;
155     (*out)->flags    = APR_INHERIT;
156     (*in)->is_pipe      =
157     (*out)->is_pipe     = 1;
158     (*out)->fname    = 
159     (*in)->fname     = NULL;
160     (*in)->buffered  =
161     (*out)->buffered = 0;
162     (*in)->blocking  =
163     (*out)->blocking = BLK_ON;
164     (*in)->timeout   =
165     (*out)->timeout  = -1;
166     (*in)->ungetchar = -1;
167     (*in)->thlock    =
168     (*out)->thlock   = NULL;
169
170     apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup,
171                          apr_pool_cleanup_null);
172     apr_pool_cleanup_register((*out)->pool, (void *)(*out), apr_unix_file_cleanup,
173                          apr_pool_cleanup_null);
174
175     return APR_SUCCESS;
176 }
177
178 APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename, 
179                                                     apr_fileperms_t perm, apr_pool_t *pool)
180 {
181     return APR_ENOTIMPL;
182
183
184     
185