Apache HTTPD
wakeup.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 "apr.h"
18#include "apr_poll.h"
19#include "apr_time.h"
20#include "apr_portable.h"
21#include "apr_arch_file_io.h"
22#include "apr_arch_networkio.h"
24#include "apr_arch_inherit.h"
25
26#if !APR_FILES_AS_SOCKETS
27
28#ifdef WIN32
29
31 apr_file_t **wakeup_pipe)
32{
33 apr_status_t rv;
34
35 if ((rv = apr_file_socket_pipe_create(&wakeup_pipe[0], &wakeup_pipe[1],
36 pool)) != APR_SUCCESS)
37 return rv;
38
39 pfd->reqevents = APR_POLLIN;
41 pfd->desc.f = wakeup_pipe[0];
42 return APR_SUCCESS;
43}
44
46{
49
50 /* Close both sides of the wakeup pipe */
51 if (wakeup_pipe[0]) {
52 rv0 = apr_file_socket_pipe_close(wakeup_pipe[0]);
53 wakeup_pipe[0] = NULL;
54 }
55 if (wakeup_pipe[1]) {
56 rv1 = apr_file_socket_pipe_close(wakeup_pipe[1]);
57 wakeup_pipe[1] = NULL;
58 }
59 return rv0 ? rv0 : rv1;
60}
61
62#else /* !WIN32 */
63
68
73
74#endif /* !WIN32 */
75
76#else /* APR_FILES_AS_SOCKETS */
77
79 apr_file_t **wakeup_pipe)
80{
81 apr_status_t rv;
82
83 if ((rv = apr_file_pipe_create_ex(&wakeup_pipe[0], &wakeup_pipe[1],
85 pool)) != APR_SUCCESS)
86 return rv;
87
88 pfd->p = pool;
89 pfd->reqevents = APR_POLLIN;
91 pfd->desc.f = wakeup_pipe[0];
92
93 {
94 int flags;
95
96 if ((flags = fcntl(wakeup_pipe[0]->filedes, F_GETFD)) == -1)
97 return errno;
98
100 if (fcntl(wakeup_pipe[0]->filedes, F_SETFD, flags) == -1)
101 return errno;
102 }
103 {
104 int flags;
105
106 if ((flags = fcntl(wakeup_pipe[1]->filedes, F_GETFD)) == -1)
107 return errno;
108
109 flags |= FD_CLOEXEC;
110 if (fcntl(wakeup_pipe[1]->filedes, F_SETFD, flags) == -1)
111 return errno;
112 }
113
114 return APR_SUCCESS;
115}
116
118{
121
122 /* Close both sides of the wakeup pipe */
123 if (wakeup_pipe[0]) {
124 rv0 = apr_file_close(wakeup_pipe[0]);
125 wakeup_pipe[0] = NULL;
126 }
127 if (wakeup_pipe[1]) {
128 rv1 = apr_file_close(wakeup_pipe[1]);
129 wakeup_pipe[1] = NULL;
130 }
131 return rv0 ? rv0 : rv1;
132}
133
134#endif /* APR_FILES_AS_SOCKETS */
135
136/* Read and discard whatever is in the wakeup pipe.
137 */
139{
140 char rb[512];
141 apr_size_t nr = sizeof(rb);
142
143 while (apr_file_read(wakeup_pipe[0], rb, &nr) == APR_SUCCESS) {
144 /* Although we write just one byte to the other end of the pipe
145 * during wakeup, multiple threads could call the wakeup.
146 * So simply drain out from the input side of the pipe all
147 * the data.
148 */
149 if (nr != sizeof(rb))
150 break;
151 }
152}
APR Poll interface.
APR Portability Routines.
APR Time Library.
#define APR_ENOTIMPL
Definition apr_errno.h:476
const char apr_ssize_t int flags
Definition apr_encode.h:168
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_POLL_FILE
Definition apr_poll.h:94
#define APR_WRITE_BLOCK
#define APR_POLLIN
Definition apr_poll.h:49
return NULL
Definition mod_so.c:359
apr_int16_t reqevents
Definition apr_poll.h:111
apr_datatype_e desc_type
Definition apr_poll.h:110
apr_descriptor desc
Definition apr_poll.h:113
apr_pool_t * p
Definition apr_poll.h:109
apr_file_t * f
Definition apr_poll.h:100
apr_status_t apr_poll_create_wakeup_pipe(apr_pollfd_t *pfd, apr_file_t **wakeup_pipe)
Definition wakeup.c:64
void apr_poll_drain_wakeup_pipe(apr_file_t **wakeup_pipe)
Definition wakeup.c:138
apr_status_t apr_poll_close_wakeup_pipe(apr_file_t **wakeup_pipe)
Definition wakeup.c:69
#define filedes
apr_status_t apr_file_socket_pipe_close(apr_file_t *file)
Definition pipe.c:470
apr_status_t apr_file_socket_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *p)
Definition pipe.c:423