[Libwebsockets] lws_close_reason with "Max connection reached" message
andy at warmcat.com
Wed Jul 6 11:58:11 CEST 2016
On Wed, 2016-07-06 at 11:27 +0200, Thomas Spitz wrote:
> When my lws server has reached its maximum of client, I am closing
> the connection abruptly using return -1 on LWS_CALLBACK_ESTABLISHED.
> I would like to give some further information to the client for the
> reason why I do that.
> I am trying to use lws_close_reason in the following way:
> > unsigned char * closeReasonData = "MAX CONNECTION REACHED!";
> > lws_close_reason(wsi,LWS_CLOSE_STATUS_NORMAL,closeReasonData,sizeof
> > (closeReasonData));
> But I get the following error:
> > ws_close_reason: Assertion `wsi->mode == LWSCM_WS_SERVING || wsi-
> > >mode == LWSCM_WS_CLIENT' failed.
> I suppose I have to set LWSCM_WS_SERVING somewhere?
No, that's an internal state about what kind of connection it is and
what it's doing, you don't have to do anything about it. Lws tracks it
from what you did with the public apis and what the connection has been
up to with its peer.
Looking at the code, he calls _ESTABLISHED callback a little bit before
setting the mode LWSCM_WS_SERVING, it used to be he would drop the ah
(header parsing info) when he changed modes is why. But that is no
longer the case since a few versions ago with the introduction of the
So there's no reason for that any more I think... I pushed a patch on
master that makes the ESTABLISHED callback come a little bit later
after the mode is set, it seems to work OK here please give it a try.
> By the way is it appropriate to use LWS_CLOSE_STATUS_NORMAL and data
> for this "Max connextion reached" purpose?
You could maybe use LWS_CLOSE_STATUS_UNEXPECTED_CONDITION maybe, NORMAL
makes it sound a bit too normal. There isn't a defined one like
TOO_BUSY or whatever. It's just for diagnostics though so probably
nothing cares either way.
> I am using master 2.0.0 from 2016/07/16
> Thanks in advance,
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
More information about the Libwebsockets