Lines 101-172
static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
Link Here
|
101 |
|
101 |
|
102 |
apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol) |
102 |
apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol) |
103 |
{ |
103 |
{ |
104 |
*protocol = sock->protocol; |
104 |
*protocol = sock->protocol; |
105 |
return APR_SUCCESS; |
105 |
return APR_SUCCESS; |
106 |
} |
106 |
} |
107 |
|
107 |
|
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 HAVE_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; |
117 |
#else |
121 |
#else |
118 |
family = APR_INET; |
122 |
family = APR_INET; |
119 |
#endif |
123 |
#endif |
120 |
} |
124 |
} |
121 |
#if APR_HAVE_SOCKADDR_UN |
125 |
#if APR_HAVE_SOCKADDR_UN |
122 |
if (family == APR_UNIX) { |
126 |
if (family == APR_UNIX) { |
123 |
protocol = 0; |
127 |
protocol = 0; |
124 |
} |
128 |
} |
125 |
#endif |
129 |
#endif |
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: |
145 |
errno = EPROTONOSUPPORT; |
149 |
errno = EPROTONOSUPPORT; |
146 |
(*new)->socketdes = -1; |
150 |
(*new)->socketdes = -1; |
147 |
break; |
151 |
break; |
148 |
} |
152 |
} |
149 |
#endif /* BEOS_R5 */ |
153 |
#endif /* BEOS_R5 */ |
150 |
|
154 |
|
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 |
|
158 |
if ((*new)->socketdes < 0) { |
162 |
if ((*new)->socketdes < 0) { |
159 |
return errno; |
163 |
return errno; |
160 |
} |
164 |
} |
161 |
set_socket_vars(*new, family, type, oprotocol); |
165 |
set_socket_vars(*new, family, type, oprotocol); |
162 |
|
166 |
|
|
|
167 |
#ifndef HAVE_SOCK_CLOEXEC |
168 |
APR_SET_FD_CLOEXEC((*new)->socketdes); |
169 |
#endif |
170 |
|
163 |
(*new)->timeout = -1; |
171 |
(*new)->timeout = -1; |
164 |
(*new)->inherit = 0; |
172 |
(*new)->inherit = 0; |
165 |
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup, |
173 |
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup, |
166 |
socket_child_cleanup); |
174 |
socket_child_cleanup); |
167 |
|
175 |
|
168 |
return APR_SUCCESS; |
176 |
return APR_SUCCESS; |
169 |
} |
177 |
} |
170 |
|
178 |
|
171 |
apr_status_t apr_socket_shutdown(apr_socket_t *thesocket, |
179 |
apr_status_t apr_socket_shutdown(apr_socket_t *thesocket, |
172 |
apr_shutdown_how_e how) |
180 |
apr_shutdown_how_e how) |
Lines 211-231
apr_status_t apr_socket_listen(apr_socket_t *sock, apr_int32_t backlog)
Link Here
|
211 |
} |
219 |
} |
212 |
|
220 |
|
213 |
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock, |
221 |
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock, |
214 |
apr_pool_t *connection_context) |
222 |
apr_pool_t *connection_context) |
215 |
{ |
223 |
{ |
216 |
int s; |
224 |
int s; |
217 |
apr_sockaddr_t sa; |
225 |
apr_sockaddr_t sa; |
218 |
|
226 |
|
219 |
sa.salen = sizeof(sa.sa); |
227 |
sa.salen = sizeof(sa.sa); |
220 |
|
228 |
|
|
|
229 |
#ifdef HAVE_ACCEPT4 |
230 |
s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC); |
231 |
#else |
221 |
s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen); |
232 |
s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen); |
|
|
233 |
#endif |
222 |
|
234 |
|
223 |
if (s < 0) { |
235 |
if (s < 0) { |
224 |
return errno; |
236 |
return errno; |
225 |
} |
237 |
} |
226 |
#ifdef TPF |
238 |
#ifdef TPF |
227 |
if (s == 0) { |
239 |
if (s == 0) { |
228 |
/* 0 is an invalid socket for TPF */ |
240 |
/* 0 is an invalid socket for TPF */ |
229 |
return APR_EINTR; |
241 |
return APR_EINTR; |
230 |
} |
242 |
} |
231 |
#endif |
243 |
#endif |
Lines 293-312
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
Link Here
|
293 |
sock->local_addr->ipaddr_len)) { |
305 |
sock->local_addr->ipaddr_len)) { |
294 |
/* If the interface address inside the listening socket's local_addr wasn't |
306 |
/* If the interface address inside the listening socket's local_addr wasn't |
295 |
* up-to-date, we don't know local interface of the connected socket either. |
307 |
* up-to-date, we don't know local interface of the connected socket either. |
296 |
* |
308 |
* |
297 |
* If the listening socket was not bound to a specific interface, we |
309 |
* If the listening socket was not bound to a specific interface, we |
298 |
* don't know the local_addr of the connected socket. |
310 |
* don't know the local_addr of the connected socket. |
299 |
*/ |
311 |
*/ |
300 |
(*new)->local_interface_unknown = 1; |
312 |
(*new)->local_interface_unknown = 1; |
301 |
} |
313 |
} |
302 |
|
314 |
|
|
|
315 |
#ifndef HAVE_ACCEPT4 |
316 |
APR_SET_FD_CLOEXEC((*new)->socketdes); |
317 |
#endif |
318 |
|
303 |
(*new)->inherit = 0; |
319 |
(*new)->inherit = 0; |
304 |
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup, |
320 |
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup, |
305 |
socket_cleanup); |
321 |
socket_cleanup); |
306 |
return APR_SUCCESS; |
322 |
return APR_SUCCESS; |
307 |
} |
323 |
} |
308 |
|
324 |
|
309 |
apr_status_t apr_socket_connect(apr_socket_t *sock, apr_sockaddr_t *sa) |
325 |
apr_status_t apr_socket_connect(apr_socket_t *sock, apr_sockaddr_t *sa) |
310 |
{ |
326 |
{ |
311 |
int rc; |
327 |
int rc; |
312 |
|
328 |
|