[Libwebsockets] multiple clients with http body using http persistent connection (PIPELINE)

dev akira akira.pp.dev at gmail.com
Fri Jan 31 23:10:53 CET 2020


Hello Andy,

Thank you for the quick update!!
I confirmed it works as expected for both GET and POST (8 clients uses 1
tls tunnel).


As far as my application where I would like to make other methods (like
PUT) also use the same tunnel, I need to add them.

diff --git a/lib/roles/http/client/client-handshake.c
b/lib/roles/http/client/client-handshake.c
index 08f5c48d..3e763820 100644
--- a/lib/roles/http/client/client-handshake.c
+++ b/lib/roles/http/client/client-handshake.c
@@ -749,7 +749,7 @@ lws_client_connect_2_dnsreq(struct lws *wsi)
        /* only pipeline things we associate with being a stream */

        if (meth && strcmp(meth, "RAW") && strcmp(meth, "GET") &&
-                   strcmp(meth, "POST"))
+                   strcmp(meth, "POST") && strcmp(meth, "PUT"))
                goto solo;

        /* consult active connections to find out disposition */
@@ -811,7 +811,7 @@ solo:
         */

        if (meth && (!strcmp(meth, "RAW") || !strcmp(meth, "GET") ||
-                    !strcmp(meth, "POST")) &&
+                    !strcmp(meth, "POST") || !strcmp(meth, "PUT")) &&
            lws_dll2_is_detached(&wsi->dll2_cli_txn_queue) &&
            lws_dll2_is_detached(&wsi->dll_cli_active_conns)) {
                lws_vhost_lock(wsi->vhost);


Thank you,
Akira

2020年1月31日(金) 16:45 Andy Green <andy at warmcat.com>:

>
>
> On 1/31/20 7:28 AM, dev akira wrote:
> > Hello Andy,
> >
> > Thank you very much for updating sample code of
> minimal-http-client-multi.
> >
> > Using the latest code (70794eaf: minimal-http-client-multi: add POST), I
> > executed "./minimal-http-client-multi -l -p --h1 --post" and confirmed
> > the multiple clients connected to the server with a single tls tunnel.
> >
> > On the other hand, when I executed "./minimal-http-client-multi -l -p -s
> > --h1 --post" (with staggered option), multiple clients use their own tls
> > tunnels.
> > Is there any way to share a single tls tunnel even for the above
> scenario?
> >
> >
> > I also confirmed the behavior of minimal-http-client-multi with staggerd
> > option using the latest code and the previous one.
>
> Thanks for the testing.
>
> > I executed "./minimal-http-client-multi -l -p -s --h1" using each code
> > and found below:
> > The latest code: 8 clients uses 8 tls tunnels.
> > The previous code: 8 clients uses 1 tls tunnel.
> >
> > Is this behavior designed?
>
> No, I forgot to transfer an asset from the "active connection leader"...
> the "leader" the other guys can queue on keeps a copy of his original
> endpoint so it can be compared with what any new guys want... now the
> leader changes that's also part of what the new leader has to inherit so
> the new leader can be understood as viable.
>
> This should fix it:
>
> diff --git a/lib/core-net/wsi.c b/lib/core-net/wsi.c
> index 8535713df..ddf389609 100644
> --- a/lib/core-net/wsi.c
> +++ b/lib/core-net/wsi.c
> @@ -844,6 +844,12 @@
> _lws_generic_transaction_completed_active_conn(struct lws **_wsi)
>          wsi->tls.use_ssl = 0;
>   #endif
>
> +       /* take over his copy of his endpoint as an active connection */
> +
> +       wnew->cli_hostname_copy = wsi->cli_hostname_copy;
> +       wsi->cli_hostname_copy = NULL;
> +
> +
>          /*
>           * selected queued guy now replaces the original leader on the
>           * active client conn list
>
> I updated yesterday's patch in place on master as well.
>
> -Andy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200201/197d1177/attachment.htm>


More information about the Libwebsockets mailing list