summaryrefslogtreecommitdiffhomepage
path: root/src/event/ngx_event_connect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/event/ngx_event_connect.c')
-rw-r--r--src/event/ngx_event_connect.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c
index 118695879..8aca86252 100644
--- a/src/event/ngx_event_connect.c
+++ b/src/event/ngx_event_connect.c
@@ -14,7 +14,7 @@
ngx_int_t
ngx_event_connect_peer(ngx_peer_connection_t *pc)
{
- int rc;
+ int rc, type;
ngx_int_t event;
ngx_err_t err;
ngx_uint_t level;
@@ -27,9 +27,12 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
return rc;
}
- s = ngx_socket(pc->sockaddr->sa_family, SOCK_STREAM, 0);
+ type = (pc->type ? pc->type : SOCK_STREAM);
- ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0, "socket %d", s);
+ s = ngx_socket(pc->sockaddr->sa_family, type, 0);
+
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, "%s socket %d",
+ (type == SOCK_STREAM) ? "stream" : "dgram", s);
if (s == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
@@ -49,6 +52,8 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
return NGX_ERROR;
}
+ c->type = type;
+
if (pc->rcvbuf) {
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
(const void *) &pc->rcvbuf, sizeof(int)) == -1)
@@ -75,25 +80,31 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
}
}
- c->recv = ngx_recv;
- c->send = ngx_send;
- c->recv_chain = ngx_recv_chain;
- c->send_chain = ngx_send_chain;
+ if (type == SOCK_STREAM) {
+ c->recv = ngx_recv;
+ c->send = ngx_send;
+ c->recv_chain = ngx_recv_chain;
+ c->send_chain = ngx_send_chain;
- c->sendfile = 1;
-
- c->log_error = pc->log_error;
+ c->sendfile = 1;
- if (pc->sockaddr->sa_family == AF_UNIX) {
- c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
- c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED;
+ if (pc->sockaddr->sa_family == AF_UNIX) {
+ c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
+ c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED;
#if (NGX_SOLARIS)
- /* Solaris's sendfilev() supports AF_NCA, AF_INET, and AF_INET6 */
- c->sendfile = 0;
+ /* Solaris's sendfilev() supports AF_NCA, AF_INET, and AF_INET6 */
+ c->sendfile = 0;
#endif
+ }
+
+ } else { /* type == SOCK_DGRAM */
+ c->recv = ngx_udp_recv;
+ c->send = ngx_send;
}
+ c->log_error = pc->log_error;
+
rev = c->read;
wev = c->write;