Klaus Demo nginx / ee4be03
ngx_create_listening() Igor Sysoev 13 years ago
4 changed file(s) with 70 addition(s) and 92 deletion(s). Raw diff Collapse all Expand all
99
1010
1111 ngx_os_io_t ngx_io;
12
13
14 ngx_listening_t *
15 ngx_create_listening(ngx_conf_t *cf, void *sockaddr, socklen_t socklen)
16 {
17 ngx_listening_t *ls;
18 struct sockaddr *sa;
19 u_char text[NGX_SOCKADDR_STRLEN];
20
21 ls = ngx_array_push(&cf->cycle->listening);
22 if (ls == NULL) {
23 return NULL;
24 }
25
26 ngx_memzero(ls, sizeof(ngx_listening_t));
27
28 sa = ngx_palloc(cf->pool, socklen);
29 if (sa == NULL) {
30 return NULL;
31 }
32
33 ngx_memcpy(sa, sockaddr, socklen);
34
35 ls->sockaddr = sa;
36 ls->socklen = socklen;
37
38 ls->addr_text.len = ngx_sock_ntop(sa, text, NGX_SOCKADDR_STRLEN, 1);
39
40 ls->addr_text.data = ngx_pnalloc(cf->pool, ls->addr_text.len);
41 if (ls->addr_text.data == NULL) {
42 return NULL;
43 }
44
45 ngx_memcpy(ls->addr_text.data, text, ls->addr_text.len);
46
47 ls->fd = (ngx_socket_t) -1;
48 ls->type = SOCK_STREAM;
49
50 switch (ls->sockaddr->sa_family) {
51 #if (NGX_HAVE_INET6)
52 case AF_INET6:
53 ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN;
54 break;
55 #endif
56 case AF_INET:
57 ls->addr_text_max_len = NGX_INET_ADDRSTRLEN;
58 break;
59 default:
60 ls->addr_text_max_len = NGX_SOCKADDR_STRLEN;
61 break;
62 }
63
64 ls->backlog = NGX_LISTEN_BACKLOG;
65 ls->rcvbuf = -1;
66 ls->sndbuf = -1;
67
68 return ls;
69 }
1270
1371
1472 ngx_int_t
162162 };
163163
164164
165 ngx_listening_t *ngx_create_listening(ngx_conf_t *cf, void *sockaddr,
166 socklen_t socklen);
165167 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
166168 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
167169 void ngx_configure_listening_sockets(ngx_cycle_t *cycle);
16871687 ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr)
16881688 {
16891689 ngx_listening_t *ls;
1690 struct sockaddr *sa;
16911690 ngx_http_core_loc_conf_t *clcf;
16921691 ngx_http_core_srv_conf_t *cscf;
1693 u_char text[NGX_SOCKADDR_STRLEN];
1694
1695 ls = ngx_array_push(&cf->cycle->listening);
1692
1693 ls = ngx_create_listening(cf, addr->sockaddr, addr->socklen);
16961694 if (ls == NULL) {
16971695 return NULL;
1698 }
1699
1700 ngx_memzero(ls, sizeof(ngx_listening_t));
1701
1702 sa = ngx_palloc(cf->pool, addr->socklen);
1703 if (sa == NULL) {
1704 return NULL;
1705 }
1706
1707 ngx_memcpy(sa, addr->sockaddr, addr->socklen);
1708
1709 ls->sockaddr = sa;
1710 ls->socklen = addr->socklen;
1711
1712 ls->addr_text.len = ngx_sock_ntop(sa, text, NGX_SOCKADDR_STRLEN, 1);
1713
1714 ls->addr_text.data = ngx_pnalloc(cf->pool, ls->addr_text.len);
1715 if (ls->addr_text.data == NULL) {
1716 return NULL;
1717 }
1718
1719 ngx_memcpy(ls->addr_text.data, text, ls->addr_text.len);
1720
1721 ls->fd = (ngx_socket_t) -1;
1722 ls->type = SOCK_STREAM;
1723
1724 switch (ls->sockaddr->sa_family) {
1725 #if (NGX_HAVE_INET6)
1726 case AF_INET6:
1727 ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN;
1728 break;
1729 #endif
1730 case AF_INET:
1731 ls->addr_text_max_len = NGX_INET_ADDRSTRLEN;
1732 break;
1733 default:
1734 ls->addr_text_max_len = NGX_SOCKADDR_STRLEN;
1735 break;
17361696 }
17371697
17381698 ls->addr_ntop = 1;
7171 ngx_listening_t *ls;
7272 ngx_mail_listen_t *mls;
7373 ngx_mail_module_t *module;
74 struct sockaddr *sa;
75 struct sockaddr_in *sin;
74 struct sockaddr_in sin;
7675 ngx_mail_in_port_t *mip;
7776 ngx_mail_conf_ctx_t *ctx;
7877 ngx_mail_conf_in_port_t *in_port;
7978 ngx_mail_conf_in_addr_t *in_addr;
8079 ngx_mail_core_srv_conf_t **cscfp;
8180 ngx_mail_core_main_conf_t *cmcf;
82 u_char buf[NGX_SOCKADDR_STRLEN];
8381
8482 if (cmd->name.data[0] == 'i') {
8583 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
301299 continue;
302300 }
303301
304 ls = ngx_array_push(&cf->cycle->listening);
302 ngx_memzero(&sin, sizeof(struct sockaddr_in));
303
304 sin.sin_family = AF_INET;
305 sin.sin_addr.s_addr = in_addr[a].addr;
306 sin.sin_port = htons(in_port[p].port);
307
308 ls = ngx_create_listening(cf, &sin, sizeof(struct sockaddr_in));
305309 if (ls == NULL) {
306310 return NULL;
307311 }
308
309 ngx_memzero(ls, sizeof(ngx_listening_t));
310
311 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
312 if (sin == NULL) {
313 return NULL;
314 }
315
316 sin->sin_family = AF_INET;
317 sin->sin_addr.s_addr = in_addr[a].addr;
318 sin->sin_port = htons(in_port[p].port);
319
320 sa = (struct sockaddr *) sin;
321
322 ls->sockaddr = sa;
323 ls->socklen = sizeof(struct sockaddr_in);
324
325 ls->addr_text.len = ngx_sock_ntop(sa, buf, NGX_SOCKADDR_STRLEN, 1);
326
327 ls->addr_text.data = ngx_pnalloc(cf->pool, ls->addr_text.len);
328 if (ls->addr_text.data == NULL) {
329 return NULL;
330 }
331
332 ngx_memcpy(ls->addr_text.data, buf, ls->addr_text.len);
333
334 ls->fd = (ngx_socket_t) -1;
335 ls->type = SOCK_STREAM;
336
337 switch (ls->sockaddr->sa_family) {
338 #if (NGX_HAVE_INET6)
339 case AF_INET6:
340 ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN;
341 break;
342 #endif
343 case AF_INET:
344 ls->addr_text_max_len = NGX_INET_ADDRSTRLEN;
345 break;
346 default:
347 ls->addr_text_max_len = NGX_SOCKADDR_STRLEN;
348 break;
349 }
350
351 ls->backlog = NGX_LISTEN_BACKLOG;
352 ls->rcvbuf = -1;
353 ls->sndbuf = -1;
354312
355313 ls->addr_ntop = 1;
356314 ls->handler = ngx_mail_init_connection;