<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>Thank you for your reply. </div><div><br></div><div>As a client oriented proxy server, nginx will boot several worker process to listen on the same port. If a tcp connection is initiated, this connection will be processed by one worker. This model is simple yet efficient. However this model makes it impossible to let nginx work as a standalone server of some protocols, for example, websocket.</div><div><br></div><div>Please let me assume it make sense to make nginx work as a standalone websock server. The problem we will face is that we cannot send message to client. Because when the client initial tcp connection, the connection will be processed by one worker uncertainly. If we want push message to one client, we must find the worker processing this client connection.</div><div><br></div><div>I have a simple idea. If we add an additional unique listen port for each http server directive before worker process do the event loop dynamically, we could use the added port to send message to client. As the listen directive is processed in the master process, it does make any help.</div><div><br></div><div>Talk is cheap. I just make a prototype at <a href="https://github.com/lvht/nginx-websocket-module">https://github.com/lvht/nginx-websocket-module</a></div><div><br></div><div>This model makes nginx as a standalone websocket server, and business logic free as soon as possible.</div><div><br></div><div>The idea of adding unique listening port dynamically is a practical solution for any protocol which need to send data to message initially, websocket, sse, http poll, etc..</div><div><br></div><div>It is also impossible to add new listening port to an http server directive dynamically in the websocket model, but it will be a huge burden to sync this logic to the http model. So I propose nginx to open this api.</div><div><br></div><div>Please forgive me for my poor English.</div><div><br></div><div>Thanks.</div><div><br>On 19 May 2017, at 01:50, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>> wrote:<br><br></div><blockquote type="cite"><div><span>Hello!</span><br><span></span><br><span>On Fri, May 19, 2017 at 01:12:29AM +0800, <a href="mailto:0@lvht.net">0@lvht.net</a> wrote:</span><br><span></span><br><blockquote type="cite"><span>Is there any maintainer who could review this patch? Thanks.</span><br></blockquote><span></span><br><span>I don't think this change is needed. Listening sockets are to be </span><br><span>created using the "listen" directive of the core module, they are </span><br><span>not expected to be added by other modules.</span><br><span></span><br><span>If you think that this is needed, you may try to convince me </span><br><span>and/or other developers by providing more details on how do you </span><br><span>want to use it and why it is needed.</span><br><span></span><br><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>在 2017年5月1日,08:31,<a href="mailto:nginx-devel-bounces@nginx.org">nginx-devel-bounces@nginx.org</a> 写道:</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span># HG changeset patch</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span># User 吕海涛 <<a href="mailto:0@lvht.net">0@lvht.net</a>></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span># Date 1493595577 -28800</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span># Mon May 01 07:39:37 2017 +0800</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span># Node ID 2ddd0894c1a6c7efe45310b874a5b4091b58bb81</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span># Parent f38647c651a8d5c884b5aacc9f9a5b1af196309b</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Http: make ngx_http_init_listening a public api</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>Make this api public is a good convenience to allow other module</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>add listening port to http server dynamically.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>diff -r f38647c651a8 -r 2ddd0894c1a6 src/http/ngx_http.c</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>--- a/src/http/ngx_http.c Thu Apr 27 16:57:18 2017 +0300</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>+++ b/src/http/ngx_http.c Mon May 01 07:39:37 2017 +0800</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>@@ -55,8 +55,6 @@ static ngx_int_t ngx_http_cmp_conf_addrs</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>static int ngx_libc_cdecl ngx_http_cmp_dns_wildcards(const void *one,</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span> const void *two);</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>-static ngx_int_t ngx_http_init_listening(ngx_conf_t *cf,</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>- ngx_http_conf_port_t *port);</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>static ngx_listening_t *ngx_http_add_listening(ngx_conf_t *cf,</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span> ngx_http_conf_addr_t *addr);</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>static ngx_int_t ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport,</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>@@ -1623,7 +1621,7 @@ ngx_http_cmp_dns_wildcards(const void *o</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>}</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>-static ngx_int_t</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>+ngx_int_t</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>{</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span> ngx_uint_t i, last, bind_wildcard;</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>diff -r f38647c651a8 -r 2ddd0894c1a6 src/http/ngx_http.h</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>--- a/src/http/ngx_http.h Thu Apr 27 16:57:18 2017 +0300</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>+++ b/src/http/ngx_http.h Mon May 01 07:39:37 2017 +0800</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>@@ -80,6 +80,7 @@ ngx_int_t ngx_http_add_location(ngx_conf</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span> ngx_http_core_loc_conf_t *clcf);</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>ngx_int_t ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span> ngx_http_listen_opt_t *lsopt);</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>+ngx_int_t ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port);</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>void ngx_http_init_connection(ngx_connection_t *c);</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>_______________________________________________</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>nginx-devel mailing list</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span><a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span><a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a></span><br></blockquote></blockquote><blockquote type="cite"><span>_______________________________________________</span><br></blockquote><blockquote type="cite"><span>nginx-devel mailing list</span><br></blockquote><blockquote type="cite"><span><a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a></span><br></blockquote><blockquote type="cite"><span><a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a></span><br></blockquote><span></span><br><span>-- </span><br><span>Maxim Dounin</span><br><span><a href="http://nginx.org/">http://nginx.org/</a></span><br><span>_______________________________________________</span><br><span>nginx-devel mailing list</span><br><span><a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a></span><br><span><a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a></span></div></blockquote></body></html>