Lines 108-116
apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol)
Link Here
|
108 |
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type, |
108 |
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type, |
109 |
int protocol, apr_pool_t *cont) |
109 |
int protocol, apr_pool_t *cont) |
110 |
{ |
110 |
{ |
111 |
int family = ofamily; |
111 |
int family = ofamily, flags = 0; |
112 |
int oprotocol = protocol; |
112 |
int oprotocol = protocol; |
113 |
|
113 |
|
|
|
114 |
#ifdef SOCK_CLOEXEC |
115 |
flags |= SOCK_CLOEXEC; |
116 |
#endif |
117 |
|
114 |
if (family == APR_UNSPEC) { |
118 |
if (family == APR_UNSPEC) { |
115 |
#if APR_HAVE_IPV6 |
119 |
#if APR_HAVE_IPV6 |
116 |
family = APR_INET6; |
120 |
family = APR_INET6; |
Lines 126-144
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
Link Here
|
126 |
alloc_socket(new, cont); |
130 |
alloc_socket(new, cont); |
127 |
|
131 |
|
128 |
#ifndef BEOS_R5 |
132 |
#ifndef BEOS_R5 |
129 |
(*new)->socketdes = socket(family, type, protocol); |
133 |
(*new)->socketdes = socket(family, type|flags, protocol); |
130 |
#else |
134 |
#else |
131 |
/* For some reason BeOS R5 has an unconventional protocol numbering, |
135 |
/* For some reason BeOS R5 has an unconventional protocol numbering, |
132 |
* so we need to translate here. */ |
136 |
* so we need to translate here. */ |
133 |
switch (protocol) { |
137 |
switch (protocol) { |
134 |
case 0: |
138 |
case 0: |
135 |
(*new)->socketdes = socket(family, type, 0); |
139 |
(*new)->socketdes = socket(family, type|flags, 0); |
136 |
break; |
140 |
break; |
137 |
case APR_PROTO_TCP: |
141 |
case APR_PROTO_TCP: |
138 |
(*new)->socketdes = socket(family, type, IPPROTO_TCP); |
142 |
(*new)->socketdes = socket(family, type|flags, IPPROTO_TCP); |
139 |
break; |
143 |
break; |
140 |
case APR_PROTO_UDP: |
144 |
case APR_PROTO_UDP: |
141 |
(*new)->socketdes = socket(family, type, IPPROTO_UDP); |
145 |
(*new)->socketdes = socket(family, type|flags, IPPROTO_UDP); |
142 |
break; |
146 |
break; |
143 |
case APR_PROTO_SCTP: |
147 |
case APR_PROTO_SCTP: |
144 |
default: |
148 |
default: |
Lines 151-157
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
Link Here
|
151 |
#if APR_HAVE_IPV6 |
155 |
#if APR_HAVE_IPV6 |
152 |
if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) { |
156 |
if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) { |
153 |
family = APR_INET; |
157 |
family = APR_INET; |
154 |
(*new)->socketdes = socket(family, type, protocol); |
158 |
(*new)->socketdes = socket(family, type|flags, protocol); |
155 |
} |
159 |
} |
156 |
#endif |
160 |
#endif |
157 |
|
161 |
|
Lines 160-165
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
Link Here
|
160 |
} |
164 |
} |
161 |
set_socket_vars(*new, family, type, oprotocol); |
165 |
set_socket_vars(*new, family, type, oprotocol); |
162 |
|
166 |
|
|
|
167 |
#ifndef SOCK_CLOEXEC |
168 |
flags = fcntl((*new)->socketdes, F_GETFD); |
169 |
if (flags == -1) |
170 |
return errno; |
171 |
flags |= FD_CLOEXEC; |
172 |
if (fcntl((*new)->socketdes, F_SETFD, flags) == -1) |
173 |
return errno; |
174 |
#endif |
175 |
|
163 |
(*new)->timeout = -1; |
176 |
(*new)->timeout = -1; |
164 |
(*new)->inherit = 0; |
177 |
(*new)->inherit = 0; |
165 |
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup, |
178 |
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup, |
Lines 213-224
apr_status_t apr_socket_listen(apr_socket_t *sock, apr_int32_t backlog)
Link Here
|
213 |
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock, |
226 |
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock, |
214 |
apr_pool_t *connection_context) |
227 |
apr_pool_t *connection_context) |
215 |
{ |
228 |
{ |
216 |
int s; |
229 |
int s, flags; |
217 |
apr_sockaddr_t sa; |
230 |
apr_sockaddr_t sa; |
218 |
|
231 |
|
219 |
sa.salen = sizeof(sa.sa); |
232 |
sa.salen = sizeof(sa.sa); |
220 |
|
233 |
|
|
|
234 |
#ifdef HAVE_ACCEPT4 |
235 |
s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC); |
236 |
#else |
221 |
s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen); |
237 |
s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen); |
|
|
238 |
#endif |
222 |
|
239 |
|
223 |
if (s < 0) { |
240 |
if (s < 0) { |
224 |
return errno; |
241 |
return errno; |
Lines 300-305
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
Link Here
|
300 |
(*new)->local_interface_unknown = 1; |
317 |
(*new)->local_interface_unknown = 1; |
301 |
} |
318 |
} |
302 |
|
319 |
|
|
|
320 |
#ifndef HAVE_ACCEPT4 |
321 |
flags = fcntl((*new)->socketdes, F_GETFD); |
322 |
if (flags == -1) |
323 |
return errno; |
324 |
flags |= FD_CLOEXEC; |
325 |
if (fcntl((*new)->socketdes, F_SETFD, flags) == -1) |
326 |
return errno; |
327 |
#endif |
328 |
|
303 |
(*new)->inherit = 0; |
329 |
(*new)->inherit = 0; |
304 |
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup, |
330 |
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup, |
305 |
socket_cleanup); |
331 |
socket_cleanup); |