Mercurial > hg > nginx
comparison src/event/ngx_event_connect.c @ 3271:fcd98af88df3
proxy_bind, fastcgi_bind, and memcached_bind
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 02 Nov 2009 15:24:02 +0000 |
parents | 042dcbaead66 |
children | d518c65ff0d4 |
comparison
equal
deleted
inserted
replaced
3270:7d1a04259e3f | 3271:fcd98af88df3 |
---|---|
52 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, | 52 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, |
53 (const void *) &pc->rcvbuf, sizeof(int)) == -1) | 53 (const void *) &pc->rcvbuf, sizeof(int)) == -1) |
54 { | 54 { |
55 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, | 55 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
56 "setsockopt(SO_RCVBUF) failed"); | 56 "setsockopt(SO_RCVBUF) failed"); |
57 | 57 goto failed; |
58 ngx_free_connection(c); | |
59 | |
60 if (ngx_close_socket(s) == -1) { | |
61 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, | |
62 ngx_close_socket_n " failed"); | |
63 } | |
64 | |
65 return NGX_ERROR; | |
66 } | 58 } |
67 } | 59 } |
68 | 60 |
69 if (ngx_nonblocking(s) == -1) { | 61 if (ngx_nonblocking(s) == -1) { |
70 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, | 62 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
71 ngx_nonblocking_n " failed"); | 63 ngx_nonblocking_n " failed"); |
72 | 64 |
73 ngx_free_connection(c); | 65 goto failed; |
74 | 66 } |
75 if (ngx_close_socket(s) == -1) { | 67 |
76 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, | 68 if (pc->local) { |
77 ngx_close_socket_n " failed"); | 69 if (bind(s, pc->local->sockaddr, pc->local->socklen) == -1) { |
78 } | 70 ngx_log_error(NGX_LOG_CRIT, pc->log, ngx_socket_errno, |
79 | 71 "bind(%V) failed", &pc->local->name); |
80 return NGX_ERROR; | 72 |
73 goto failed; | |
74 } | |
81 } | 75 } |
82 | 76 |
83 c->recv = ngx_recv; | 77 c->recv = ngx_recv; |
84 c->send = ngx_send; | 78 c->send = ngx_send; |
85 c->recv_chain = ngx_recv_chain; | 79 c->recv_chain = ngx_recv_chain; |
125 wev->own_lock = &c->lock; | 119 wev->own_lock = &c->lock; |
126 #endif | 120 #endif |
127 | 121 |
128 if (ngx_add_conn) { | 122 if (ngx_add_conn) { |
129 if (ngx_add_conn(c) == NGX_ERROR) { | 123 if (ngx_add_conn(c) == NGX_ERROR) { |
130 return NGX_ERROR; | 124 goto failed; |
131 } | 125 } |
132 } | 126 } |
133 | 127 |
134 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pc->log, 0, | 128 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pc->log, 0, |
135 "connect to %V, fd:%d #%d", pc->name, s, c->number); | 129 "connect to %V, fd:%d #%d", pc->name, s, c->number); |
197 /* aio, iocp */ | 191 /* aio, iocp */ |
198 | 192 |
199 if (ngx_blocking(s) == -1) { | 193 if (ngx_blocking(s) == -1) { |
200 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, | 194 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
201 ngx_blocking_n " failed"); | 195 ngx_blocking_n " failed"); |
202 return NGX_ERROR; | 196 goto failed; |
203 } | 197 } |
204 | 198 |
205 /* | 199 /* |
206 * FreeBSD's aio allows to post an operation on non-connected socket. | 200 * FreeBSD's aio allows to post an operation on non-connected socket. |
207 * NT does not support it. | 201 * NT does not support it. |
227 | 221 |
228 event = NGX_LEVEL_EVENT; | 222 event = NGX_LEVEL_EVENT; |
229 } | 223 } |
230 | 224 |
231 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { | 225 if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { |
232 return NGX_ERROR; | 226 goto failed; |
233 } | 227 } |
234 | 228 |
235 if (rc == -1) { | 229 if (rc == -1) { |
236 | 230 |
237 /* NGX_EINPROGRESS */ | 231 /* NGX_EINPROGRESS */ |
238 | 232 |
239 if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) { | 233 if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) { |
240 return NGX_ERROR; | 234 goto failed; |
241 } | 235 } |
242 | 236 |
243 return NGX_AGAIN; | 237 return NGX_AGAIN; |
244 } | 238 } |
245 | 239 |
246 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected"); | 240 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected"); |
247 | 241 |
248 wev->ready = 1; | 242 wev->ready = 1; |
249 | 243 |
250 return NGX_OK; | 244 return NGX_OK; |
245 | |
246 failed: | |
247 | |
248 ngx_free_connection(c); | |
249 | |
250 if (ngx_close_socket(s) == -1) { | |
251 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, | |
252 ngx_close_socket_n " failed"); | |
253 } | |
254 | |
255 return NGX_ERROR; | |
251 } | 256 } |
252 | 257 |
253 | 258 |
254 ngx_int_t | 259 ngx_int_t |
255 ngx_event_get_peer(ngx_peer_connection_t *pc, void *data) | 260 ngx_event_get_peer(ngx_peer_connection_t *pc, void *data) |