Klaus Demo nginx / 6efa56f
delete ngx_listening_inet_stream_socket() Igor Sysoev 13 years ago
3 changed file(s) with 47 addition(s) and 51 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_listening_inet_stream_socket(ngx_conf_t *cf, in_addr_t addr, in_port_t port)
16 {
17 size_t len;
18 ngx_listening_t *ls;
19 struct sockaddr_in *sin;
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 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
29 if (sin == NULL) {
30 return NULL;
31 }
32
33 sin->sin_family = AF_INET;
34 sin->sin_addr.s_addr = addr;
35 sin->sin_port = htons(port);
36
37
38 ls->addr_text.data = ngx_pnalloc(cf->pool,
39 NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1);
40 if (ls->addr_text.data == NULL) {
41 return NULL;
42 }
43
44 len = ngx_inet_ntop(AF_INET, &addr, ls->addr_text.data,
45 NGX_INET_ADDRSTRLEN);
46
47 ls->addr_text.len = ngx_sprintf(ls->addr_text.data + len, ":%d", port)
48 - ls->addr_text.data;
49
50 ls->fd = (ngx_socket_t) -1;
51 ls->type = SOCK_STREAM;
52 ls->sockaddr = (struct sockaddr *) sin;
53 ls->socklen = sizeof(struct sockaddr_in);
54 ls->addr_text_max_len = NGX_INET_ADDRSTRLEN;
55
56 return ls;
57 }
5812
5913
6014 ngx_int_t
167167 #endif
168168
169169
170 ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
171 in_addr_t addr, in_port_t port);
172170 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
173171 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
174172 void ngx_configure_listening_socket(ngx_cycle_t *cycle);
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;
7476 ngx_mail_in_port_t *mip;
7577 ngx_mail_conf_ctx_t *ctx;
7678 ngx_mail_conf_in_port_t *in_port;
7779 ngx_mail_conf_in_addr_t *in_addr;
7880 ngx_mail_core_srv_conf_t **cscfp;
7981 ngx_mail_core_main_conf_t *cmcf;
82 u_char buf[NGX_SOCKADDR_STRLEN];
8083
8184 if (cmd->name.data[0] == 'i') {
8285 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
298301 continue;
299302 }
300303
301 ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr,
302 in_port[p].port);
304 ls = ngx_array_push(&cf->cycle->listening);
303305 if (ls == NULL) {
304 return NGX_CONF_ERROR;
306 return NULL;
307 }
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;
305349 }
306350
307351 ls->backlog = NGX_LISTEN_BACKLOG;