comparison src/core/ngx_listen.c @ 0:4eff17414a43

nginx-0.0.1-2002-08-06-20:39:45 import The first code that uses "ngx_" prefix, the previous one used "gx_" prefix. At that point the code is not yet usable. The first draft ideas are dated back to 23.10.2001.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 06 Aug 2002 16:39:45 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4eff17414a43
1
2 #include <ngx_config.h>
3 #include <ngx_types.h>
4 #include <ngx_errno.h>
5 #include <ngx_log.h>
6 #include <ngx_listen.h>
7
8 ngx_socket_t ngx_listen(struct sockaddr *addr, int backlog,
9 ngx_log_t *log, char *addr_text)
10 {
11 ngx_socket_t s;
12 int reuseaddr = 1;
13 #if (WIN32)
14 unsigned long nb = 1;
15 #endif
16
17 if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
18 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, "socket failed");
19
20 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
21 (const void *) &reuseaddr, sizeof(int)) == -1)
22 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
23 "ngx_listen: setsockopt (SO_REUSEADDR) failed");
24
25 #if (WIN32)
26 if (ioctlsocket(s, FIONBIO, &nb) == -1)
27 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
28 "ngx_listen: ioctlsocket (FIONBIO) failed");
29 #else
30 if (fcntl(s, F_SETFL, O_NONBLOCK) == -1)
31 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
32 "ngx_listen: fcntl (O_NONBLOCK) failed");
33 #endif
34
35 if (bind(s, (struct sockaddr *) addr, sizeof(struct sockaddr_in)) == -1)
36 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
37 "ngx_listen: bind to %s failed", addr_text);
38
39 if (listen(s, backlog) == -1)
40 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
41 "ngx_listen: listen to %s failed", addr_text);
42
43 return s;
44 }