Mercurial > hg > nginx
comparison src/mail/ngx_mail.c @ 2806:a445bd4eb571
ngx_create_listening()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 05 May 2009 17:33:26 +0000 |
parents | 8b54548fef6e |
children | a96a8c916b0c |
comparison
equal
deleted
inserted
replaced
2805:60551422e150 | 2806:a445bd4eb571 |
---|---|
70 ngx_conf_t pcf; | 70 ngx_conf_t pcf; |
71 ngx_array_t in_ports; | 71 ngx_array_t in_ports; |
72 ngx_listening_t *ls; | 72 ngx_listening_t *ls; |
73 ngx_mail_listen_t *mls; | 73 ngx_mail_listen_t *mls; |
74 ngx_mail_module_t *module; | 74 ngx_mail_module_t *module; |
75 struct sockaddr *sa; | 75 struct sockaddr_in sin; |
76 struct sockaddr_in *sin; | |
77 ngx_mail_in_port_t *mip; | 76 ngx_mail_in_port_t *mip; |
78 ngx_mail_conf_ctx_t *ctx; | 77 ngx_mail_conf_ctx_t *ctx; |
79 ngx_mail_conf_in_port_t *in_port; | 78 ngx_mail_conf_in_port_t *in_port; |
80 ngx_mail_conf_in_addr_t *in_addr; | 79 ngx_mail_conf_in_addr_t *in_addr; |
81 ngx_mail_core_srv_conf_t **cscfp; | 80 ngx_mail_core_srv_conf_t **cscfp; |
82 ngx_mail_core_main_conf_t *cmcf; | 81 ngx_mail_core_main_conf_t *cmcf; |
83 u_char buf[NGX_SOCKADDR_STRLEN]; | |
84 | 82 |
85 if (cmd->name.data[0] == 'i') { | 83 if (cmd->name.data[0] == 'i') { |
86 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | 84 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
87 "the \"imap\" directive is deprecated, " | 85 "the \"imap\" directive is deprecated, " |
88 "use the \"mail\" directive instead"); | 86 "use the \"mail\" directive instead"); |
300 if (!bind_all && !in_addr[a].bind) { | 298 if (!bind_all && !in_addr[a].bind) { |
301 a++; | 299 a++; |
302 continue; | 300 continue; |
303 } | 301 } |
304 | 302 |
305 ls = ngx_array_push(&cf->cycle->listening); | 303 ngx_memzero(&sin, sizeof(struct sockaddr_in)); |
304 | |
305 sin.sin_family = AF_INET; | |
306 sin.sin_addr.s_addr = in_addr[a].addr; | |
307 sin.sin_port = htons(in_port[p].port); | |
308 | |
309 ls = ngx_create_listening(cf, &sin, sizeof(struct sockaddr_in)); | |
306 if (ls == NULL) { | 310 if (ls == NULL) { |
307 return NULL; | 311 return NULL; |
308 } | 312 } |
309 | |
310 ngx_memzero(ls, sizeof(ngx_listening_t)); | |
311 | |
312 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)); | |
313 if (sin == NULL) { | |
314 return NULL; | |
315 } | |
316 | |
317 sin->sin_family = AF_INET; | |
318 sin->sin_addr.s_addr = in_addr[a].addr; | |
319 sin->sin_port = htons(in_port[p].port); | |
320 | |
321 sa = (struct sockaddr *) sin; | |
322 | |
323 ls->sockaddr = sa; | |
324 ls->socklen = sizeof(struct sockaddr_in); | |
325 | |
326 ls->addr_text.len = ngx_sock_ntop(sa, buf, NGX_SOCKADDR_STRLEN, 1); | |
327 | |
328 ls->addr_text.data = ngx_pnalloc(cf->pool, ls->addr_text.len); | |
329 if (ls->addr_text.data == NULL) { | |
330 return NULL; | |
331 } | |
332 | |
333 ngx_memcpy(ls->addr_text.data, buf, ls->addr_text.len); | |
334 | |
335 ls->fd = (ngx_socket_t) -1; | |
336 ls->type = SOCK_STREAM; | |
337 | |
338 switch (ls->sockaddr->sa_family) { | |
339 #if (NGX_HAVE_INET6) | |
340 case AF_INET6: | |
341 ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN; | |
342 break; | |
343 #endif | |
344 case AF_INET: | |
345 ls->addr_text_max_len = NGX_INET_ADDRSTRLEN; | |
346 break; | |
347 default: | |
348 ls->addr_text_max_len = NGX_SOCKADDR_STRLEN; | |
349 break; | |
350 } | |
351 | |
352 ls->backlog = NGX_LISTEN_BACKLOG; | |
353 ls->rcvbuf = -1; | |
354 ls->sndbuf = -1; | |
355 | 313 |
356 ls->addr_ntop = 1; | 314 ls->addr_ntop = 1; |
357 ls->handler = ngx_mail_init_connection; | 315 ls->handler = ngx_mail_init_connection; |
358 ls->pool_size = 256; | 316 ls->pool_size = 256; |
359 | 317 |