[Libwebsockets] new context_info structs

Jack Mitchell ml at communistcode.co.uk
Mon Feb 11 17:21:47 CET 2013


On 11/02/13 16:06, "Andy Green (林安廸)" wrote:
> On 11/02/13 23:55, the mail apparently from Jack Mitchell included:
>> On 11/02/13 15:47, "Andy Green (林安廸)" wrote:
>>> On 11/02/13 23:38, the mail apparently from Jack Mitchell included:
>>>> On 11/02/13 15:14, "Andy Green (林安廸)" wrote:
> ...
>>>> Program received signal SIGSEGV, Segmentation fault.
>>>> libwebsocket_callback_on_writable_all_protocol
>>>> (protocol=protocol at entry=0x1d374 <systemConf+96>)
>>>>      at libwebsockets.c:1342
>>>> 1342        for (n = 0; n < context->fds_count; n++) {
>>>> (gdb) bt
>>>> #0  libwebsocket_callback_on_writable_all_protocol
>>>> (protocol=protocol at entry=0x1d374 <systemConf+96>)
>>>>      at libwebsockets.c:1342
>>>> #1  0x0000e0ac in webSock_broadcastJsonObject (jsonObj=0x1b9b48,
>>>> card=card at entry=0x1d314 <systemConf>)
>>>>      at webInterfaces/webInterface_webSockets.c:250
>>>> #2  0x0000f408 in controlWeb_setCardStatus (card=card at entry=0x1d314
>>>> <systemConf>, status=status at entry=CARD_AVAILABLE)
>>>>      at controlWeb/controlWeb.c:90
>>>> #3  0x0000a548 in r0005_initCard (card=0x1d314 <systemConf>) at
>>>> R0005.c:197
>>>> #4  0x0000a1c0 in main () at R0005.c:65
>>>>
>>>>
>>>> Valgrind:
>>>>
>>>> [946688211:2171] NOTICE: Initial logging level 15
>>>> [946688211:2196] NOTICE: Library version: 1.1 224149a
>>>> [946688211:2226] INFO:  LWS_MAX_HEADER_NAME_LENGTH: 64
>>>> [946688211:2244] INFO:  LWS_MAX_HEADER_LEN: 1024
>>>> [946688211:2262] INFO:  LWS_MAX_PROTOCOLS: 5
>>>> [946688211:2279] INFO:  LWS_MAX_EXTENSIONS_ACTIVE: 3
>>>> [946688211:2296] INFO:  SPEC_LATEST_SUPPORTED: 13
>>>> [946688211:2312] INFO:  AWAITING_TIMEOUT: 5
>>>> [946688211:2327] INFO:  CIPHERS_LIST_STRING: 'DEFAULT'
>>>> [946688211:2345] INFO:  SYSTEM_RANDOM_FILEPATH: '/dev/urandom'
>>>> [946688211:2362] INFO:  LWS_MAX_ZLIB_CONN_BUFFER: 65536
>>>> [946688211:2383] NOTICE:  static allocation: 5460 + (12 x 1024 fds) =
>>>> 17748 bytes
>>>> [946688211:2608] NOTICE:  canonical_hostname =
>>>> 97-103-108-101.res.bhn.net
>>>> [946688211:2631] NOTICE:  Compiled without SSL support
>>>> [946688211:2651] NOTICE:  per-conn mem: 172 + 1328 headers + 
>>>> protocol rx
>>>> buf
>>>> [946688211:2677] INFO: insert_wsi_socket_into_fds: wsi=0x4b08de0,
>>>> sock=14, fds pos=0
>>>> [946688211:2717] NOTICE:  Listening on port 8000
>>>>
>>>> ==470== Invalid read of size 4
>>>> ==470==    at 0x498BD34: 
>>>> libwebsocket_callback_on_writable_all_protocol
>>>> (libwebsockets.c:1342)
>>>> ==470==    by 0xE0AB: webSock_broadcastJsonObject
>>>> (webInterface_webSockets.c:250)
>>>> ==470==    by 0xF407: controlWeb_setCardStatus (controlWeb.c:90)
>>>> ==470==    by 0xA547: r0005_initCard (R0005.c:197)
>>>> ==470==    by 0xA1BF: main (R0005.c:65)
>>>> ==470==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
>>>> ==470==
>>>> ==470==
>>>> ==470== Process terminating with default action of signal 11 (SIGSEGV)
>>>> ==470==  Access not within mapped region at address 0x8
>>>> ==470==    at 0x498BD34: 
>>>> libwebsocket_callback_on_writable_all_protocol
>>>> (libwebsockets.c:1342)
>>>> ==470==    by 0xE0AB: webSock_broadcastJsonObject
>>>> (webInterface_webSockets.c:250)
>>>> ==470==    by 0xF407: controlWeb_setCardStatus (controlWeb.c:90)
>>>> ==470==    by 0xA547: r0005_initCard (R0005.c:197)
>>>> ==470==    by 0xA1BF: main (R0005.c:65)
>>>
>>> I guess the "owning server" of the protocol is NULL
>>>
>>> Can you change the log here (libwebsockets.c:2112) to lwsl_notice and
>>> see if this is actually getting executed
>>>
>>>
>>>     /* initialize supported protocols */
>>>
>>>     for (context->count_protocols = 0;
>>> info->protocols[context->count_protocols].callback;
>>>                            context->count_protocols++) {
>>>
>>>         lwsl_parser("  Protocol: %s\n",
>>> info->protocols[context->count_protocols].name);
>>>
>>> info->protocols[context->count_protocols].owning_server =
>>>                                     context;
>>> info->protocols[context->count_protocols].protocol_index =
>>>                                context->count_protocols;
>>>
>>>         /*
>>>          * inform all the protocols that they are doing their one-time
>>>          * initialization if they want to
>>>          */
>>> info->protocols[context->count_protocols].callback(context,
>>>                    NULL, LWS_CALLBACK_PROTOCOL_INIT, NULL, NULL, 0);
>>>     }
>>>
>>> Are we checking if the context that was created is NULL, ie, it failed?
>>>
>>> -Andy
>>>
>>
>> Yes, check for NULL is in place.
>>
>> With modification:
>>
>> [946689226:8809] NOTICE:   Protocol: http-only
>> [946689226:8811] NOTICE:   Protocol: send-receive-value
>
> Are we calling libwebsocket_callback_on_writable_all_protocol() from a 
> different fork than did the context creation?
>
> What does the code at webSock_broadcastJsonObject look like, how does 
> it provide the protocol pointer to 
> libwebsocket_callback_on_writable_all_protocol?

Apologies, my libwebsocket_callback_on_writable_all_protocol was 
pointing to the old location of the protocol struct which I still had 
defined in my t_cardConfig definition, but not populated. Sorry for 
wasting your time!

>
> Does the test server and client work OK?
>
> -Andy


-- 

   Jack Mitchell (jack at embed.me.uk)
   Embedded Systems Engineer
   http://www.embed.me.uk

--




More information about the Libwebsockets mailing list