Mercurial > hg > nginx
comparison src/event/ngx_event_connect.c @ 6436:8f038068f4bc
Stream: UDP proxy.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 20 Jan 2016 19:52:12 +0300 |
parents | 4dc8e7b62216 |
children | 1d0e03db9f8e |
comparison
equal
deleted
inserted
replaced
6435:d1c791479bbb | 6436:8f038068f4bc |
---|---|
12 | 12 |
13 | 13 |
14 ngx_int_t | 14 ngx_int_t |
15 ngx_event_connect_peer(ngx_peer_connection_t *pc) | 15 ngx_event_connect_peer(ngx_peer_connection_t *pc) |
16 { | 16 { |
17 int rc; | 17 int rc, type; |
18 ngx_int_t event; | 18 ngx_int_t event; |
19 ngx_err_t err; | 19 ngx_err_t err; |
20 ngx_uint_t level; | 20 ngx_uint_t level; |
21 ngx_socket_t s; | 21 ngx_socket_t s; |
22 ngx_event_t *rev, *wev; | 22 ngx_event_t *rev, *wev; |
25 rc = pc->get(pc, pc->data); | 25 rc = pc->get(pc, pc->data); |
26 if (rc != NGX_OK) { | 26 if (rc != NGX_OK) { |
27 return rc; | 27 return rc; |
28 } | 28 } |
29 | 29 |
30 s = ngx_socket(pc->sockaddr->sa_family, SOCK_STREAM, 0); | 30 type = (pc->type ? pc->type : SOCK_STREAM); |
31 | 31 |
32 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0, "socket %d", s); | 32 s = ngx_socket(pc->sockaddr->sa_family, type, 0); |
33 | |
34 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, "%s socket %d", | |
35 (type == SOCK_STREAM) ? "stream" : "dgram", s); | |
33 | 36 |
34 if (s == (ngx_socket_t) -1) { | 37 if (s == (ngx_socket_t) -1) { |
35 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, | 38 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
36 ngx_socket_n " failed"); | 39 ngx_socket_n " failed"); |
37 return NGX_ERROR; | 40 return NGX_ERROR; |
46 ngx_close_socket_n "failed"); | 49 ngx_close_socket_n "failed"); |
47 } | 50 } |
48 | 51 |
49 return NGX_ERROR; | 52 return NGX_ERROR; |
50 } | 53 } |
54 | |
55 c->type = type; | |
51 | 56 |
52 if (pc->rcvbuf) { | 57 if (pc->rcvbuf) { |
53 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, | 58 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, |
54 (const void *) &pc->rcvbuf, sizeof(int)) == -1) | 59 (const void *) &pc->rcvbuf, sizeof(int)) == -1) |
55 { | 60 { |
73 | 78 |
74 goto failed; | 79 goto failed; |
75 } | 80 } |
76 } | 81 } |
77 | 82 |
78 c->recv = ngx_recv; | 83 if (type == SOCK_STREAM) { |
79 c->send = ngx_send; | 84 c->recv = ngx_recv; |
80 c->recv_chain = ngx_recv_chain; | 85 c->send = ngx_send; |
81 c->send_chain = ngx_send_chain; | 86 c->recv_chain = ngx_recv_chain; |
82 | 87 c->send_chain = ngx_send_chain; |
83 c->sendfile = 1; | 88 |
89 c->sendfile = 1; | |
90 | |
91 if (pc->sockaddr->sa_family == AF_UNIX) { | |
92 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; | |
93 c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED; | |
94 | |
95 #if (NGX_SOLARIS) | |
96 /* Solaris's sendfilev() supports AF_NCA, AF_INET, and AF_INET6 */ | |
97 c->sendfile = 0; | |
98 #endif | |
99 } | |
100 | |
101 } else { /* type == SOCK_DGRAM */ | |
102 c->recv = ngx_udp_recv; | |
103 c->send = ngx_send; | |
104 } | |
84 | 105 |
85 c->log_error = pc->log_error; | 106 c->log_error = pc->log_error; |
86 | |
87 if (pc->sockaddr->sa_family == AF_UNIX) { | |
88 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; | |
89 c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED; | |
90 | |
91 #if (NGX_SOLARIS) | |
92 /* Solaris's sendfilev() supports AF_NCA, AF_INET, and AF_INET6 */ | |
93 c->sendfile = 0; | |
94 #endif | |
95 } | |
96 | 107 |
97 rev = c->read; | 108 rev = c->read; |
98 wev = c->write; | 109 wev = c->write; |
99 | 110 |
100 rev->log = pc->log; | 111 rev->log = pc->log; |