[Libwebsockets] insert_wsi_socket_into_fds and lws_lookup

Simon nononame at le-huit.fr
Tue Jan 14 10:06:07 CET 2014


Le 11/01/2014 06:17, "Andy Green (林安廸)" a écrit :
> On 07/01/14 20:57, the mail apparently from Simon B included:
>> My comment is about "insert_wsi_socket_into_fds" function in
>> libwebsockets.c
>>
>> lws_lookup allocation is
>>
>>      context->lws_lookup = (struct libwebsocket **)
>>                malloc(sizeof(struct libwebsocket *) * context->max_fds);
>>
>> In the function "insert_wsi_socket_into_fds" we need
>>    wsi->sock < context->max_fds
>> because we do
>>    context->lws_lookup[wsi->sock] = wsi;
>>
>> this is protected by
>>      if (wsi->sock > context->max_fds) {
>>          lwsl_err("Socket fd %d is too high (%d)\n",
>>                          wsi->sock, context->max_fds);
>>          return 1;
>>      }
>> but I think we need protect by
>>      if (wsi->sock >= context->max_fds)
>
> Thanks for your patch about that.
>
>> An other comment is about the return of the callback
>> LWS_CALLBACK_ADD_POLL_FD in the same function.
>> In test-server.c (when EXTERNAL_POLL is define), the callback of
>> LWS_CALLBACK_ADD_POLL_FD can return 0 or 1
>>          if (count_pollfds >= max_poll_elements) {
>>              lwsl_err("LWS_CALLBACK_ADD_POLL_FD: too many sockets to
>> track\n");
>>              return 1;
>>          }
>> this example server return 1 to refuse the connection but in
>> libwebsockets.c (in function insert_wsi_socket_into_fds),
>> the result callback is not read. Why ?
>
> Because we were too dumb to check it I guess ^^
>
> Would you like to provide a patch to check it?
>
> thanks
>
> -Andy
>
>> Excuse my bad English.
>> Simon
>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>

I work on a patch to check insert_wsi_socket_into_fds return. But there 
are 2 different problemes:
   What do when accept can't return a file descriptor -> google: "accept 
EMFILE loop".
(accept return error EMFILE, and poll doesn't stop to event on the 
socket listen).
   return insert_wsi_socket_into_fds and LWS_CALLBACK_ADD_POLL_FD 
analyse. I prepare a patch.

PS: I found memory never free data. we need to free header before to 
free wsi (not always do). I prepare a patch.

Simon



More information about the Libwebsockets mailing list