~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/file_io/netware/pipe.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * 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
    (void) apr_pollset_create(&(*in)->pollset, 1, pool, 0);
 
170
    (void) apr_pollset_create(&(*out)->pollset, 1, pool, 0);
 
171
 
 
172
    apr_pool_cleanup_register((*in)->pool, (void *)(*in), apr_unix_file_cleanup,
 
173
                         apr_pool_cleanup_null);
 
174
    apr_pool_cleanup_register((*out)->pool, (void *)(*out), apr_unix_file_cleanup,
 
175
                         apr_pool_cleanup_null);
 
176
 
 
177
    return APR_SUCCESS;
 
178
}
 
179
 
 
180
APR_DECLARE(apr_status_t) apr_file_namedpipe_create(const char *filename, 
 
181
                                                    apr_fileperms_t perm, apr_pool_t *pool)
 
182
{
 
183
    return APR_ENOTIMPL;
 
184
 
185
 
 
186
    
 
187