[Libwebsockets] Sending from the receive callback

lws14 at mordent.com lws14 at mordent.com
Sat Aug 2 19:51:19 CEST 2014


What is p pointing to?  Is it a buffer that contains space for padding?  
You have to make sure you include padding as in the example code.

-m

On 8/1/2014 8:17 PM, Steve Calfee wrote:
> I am doing a very simple protocol. The browser sends a chunk of data, the server is supposed to echo back "ok" for each chunk. I am not doing anything with the data, just reporting that I got it. The code below is from the simple dumb-increment protocol example, with the changes for the protocol.
>
> callback_upload_protocol(struct libwebsocket_context *context,
>                              struct libwebsocket *wsi,
>                              enum libwebsocket_callback_reasons reason,
>                              void *user, void *in, size_t len)
>
>      case LWS_CALLBACK_SERVER_WRITEABLE:
>          n = sprintf((char *)p, "ok");
>          lwsl_notice("webwrite %d UPLOAD send= %s\n", n, p);
>
>          m = libwebsocket_write(wsi, (unsigned char *)p, n, LWS_WRITE_TEXT);
>          lwsl_notice("libwebsockets upload write %s\n", p);
>          if (m < n) {
>              lwsl_err("ERROR %d writing to fl socket\n", n);
>              return -1;
>          }
>          break;
>      case LWS_CALLBACK_RECEIVE:
>              lwsl_notice("libwebsockets upload receive %d bytes\n", len);
>              libwebsocket_callback_on_writable(context, wsi);
>          break;
>
> The problem is if I send a very small chunk of data, around 10K, the notice prints that it received the data. But I never get the writeable callback.
>
> My main loop spends most of its time idling and calling:
>              (void) libwebsocket_service(context, timer);
>
> I guess I don't understand the interaction between the main loop and the libwebsockets library. Does my callback have to do something to keep reading? Do I have to free anything, like the data the "in" ptr is pointing to? What would prevent a socket from becoming writeable?
>
> Thanks, Steve
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list