Mercurial > hg > nginx-quic
diff src/core/nginx.c @ 1:d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 15 Aug 2002 17:20:26 +0000 |
parents | 4eff17414a43 |
children | ffffe1499bce |
line wrap: on
line diff
--- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -25,7 +25,7 @@ int ngx_http_init_connection(void *data) int ngx_max_conn = 512; struct sockaddr_in ngx_addr = {0, AF_INET, 0, 0, 0}; - +int ngx_backlog = 0; ngx_pool_t ngx_pool; ngx_log_t ngx_log; @@ -35,10 +35,12 @@ ngx_server_t ngx_server; int main(int argc, char *const *argv) { char addr_text[22]; - ngx_socket_t fd; + ngx_socket_t s; ngx_listen_t ls; + int reuseaddr = 1; #if (WIN32) WSADATA wsd; + unsigned long nb = 1; #endif @@ -61,16 +63,45 @@ int main(int argc, char *const *argv) "WSAStartup failed"); #endif + /* for each listening socket */ + s = socket(AF_INET, SOCK_STREAM, 0); + if (s == -1) + ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno, + "socket failed"); + + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, + (const void *) &reuseaddr, sizeof(int)) == -1) + ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno, + "setsockopt (SO_REUSEADDR) failed"); + +#if (WIN32) + if (ioctlsocket(s, FIONBIO, &nb) == -1) + ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno, + "ioctlsocket (FIONBIO) failed"); +#else + if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) + ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno, + "fcntl (O_NONBLOCK) failed"); +#endif + ngx_snprintf(ngx_cpystrn(addr_text, inet_ntoa(ngx_addr.sin_addr), 16), 7, ":%d", ntohs(ngx_addr.sin_port)); - fd = ngx_listen((struct sockaddr *) &ngx_addr, -1, &ngx_log, addr_text); + + if (bind(s, (struct sockaddr *) &ngx_addr, + sizeof(struct sockaddr_in)) == -1) + ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno, + "bind to %s failed", addr_text); + + if (listen(s, ngx_backlog) == -1) + ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno, + "listen to %s failed", addr_text); ngx_server.buff_size = 1024; ngx_server.handler = ngx_http_init_connection; /* daemon */ - ls.fd = fd; + ls.fd = s; ls.server = &ngx_server; ls.log = &ngx_log;