[Libwebsockets] About returning -1 from callback and the pointer to the struct libwebsocket.

Andy Green andy at warmcat.com
Sat Jul 5 05:06:14 CEST 2014



On 05/25/2014 12:22 AM, Armando Baños wrote:
> Hi:
>
> I'm using libwebsocket as client and when I reach the point of closing
> the connection I'm using the method proposed in the documentation of
> returning -1 from the callback LWS_CALLBACK_CLIENT_WRITEABLE. That's
> going fine but the problem is that after the return from the callback,
> even when I have received the last callback (LWS_CALLBACK_CLOSED or
> one of the callbacks related with POLL_FD) the pointer to the
> libwebsocket struct that represents the connection never gets NULL (I
> have wait even 5 minutes writting the pointer value to the syslog).

I'm not sure what this pointer is?

> It's something wrong in what I'm doing that does not close the
> connection right? or it's normal that when the internal function
> "libwebsocket_close_and_free_session" ends it does not NULLs the
> pointer.
>
> Any way, in case that behaviour is right, how can I know for sure that
> the connection was properly closed and that the struct libwebsocket
> pointed to by my wsi variable was properly freed?

You should only interact with wsi's inside the callback.  So when it's 
closed, you won't get any more callbacks.

Even when the close_and_free_session() defers the actual close and free, 
he sets a 5s timeout on the wsi at that time.  So he should always be 
gone after 5s.

At that time he doesn't have an idea to NULL anything about the wsi just 
free it.  Likewise the place in the poll() tables is replaced by another 
wsi or becomes unused.

-Andy

> waiting a positive answer:
> Armando.
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>



More information about the Libwebsockets mailing list