[Libwebsockets] [libwebsockets] #88: Socket close by client

Trac trac at libwebsockets.org
Wed Oct 1 19:57:52 CEST 2014


#88: Socket close by client
-----------------------------------+-----------------
 Reporter:  marcin                 |      Owner:
     Type:  enhancement            |     Status:  new
 Priority:  minor                  |  Milestone:
Component:  libwebsockets library  |    Version:
 Keywords:                         |
-----------------------------------+-----------------
 I use in my application the libwesockets and I think it's very useful
 library. In my multithreaded application I have this code:

 case LWS_CALLBACK_SERVER_WRITEABLE:
                         '''messageEntry = messageQueue->pop();'''
                         if(messageEntry != NULL) {
                                 libwebsocket_write(wsi, (unsigned
 char*)messageEntry->getJsonString()->c_str(), messageEntry->length(),
 LWS_WRITE_TEXT);
                                 delete messageEntry;
                         }

 ...

 while (true) {
                 libwebsocket_service(context, 10);
                 '''messageEntry = messageQueue->front();'''
                 if(messageEntry != NULL)
                         libwebsocket_callback_on_writable(context,
 messageEntry->wsi);
 }

 I have question how can I figure out that a client close the connection?
 In the loop "while(true)" I'm checking only if there is a new message (but
 the message is not getting from the queue) and if it is then I call
 "libwebsocket_callback_on_writable".
 If client is connected, there is "LWS_CALLBACK_SERVER_WRITEABLE" callback
 but otherwise there is no callback at all and the message is not getting
 from the messageQueue.

 I tryed change the code:
 if(messageEntry != NULL) {
                         if(messageEntry->wsi->state ==
 WSI_STATE_DEAD_SOCKET)
                                 /* then pop a message */
                         else
                                 libwebsocket_callback_on_writable(context,
 messageEntry->wsi);
 }

 But when I try compile the code I see the error:
 "error: invalid use of incomplete type ‘struct libwebsocket’"

 Any suggestions how can I solve the problem? And does it good idea to use
 "wsi->state" to check client connection state?

--
Ticket URL: <http://libwebsockets.org/trac/libwebsockets/ticket/88>
libwebsockets <http://libwebsockets.org>
libwebsockets C library



More information about the Libwebsockets mailing list