[Libwebsockets] How to get wsi reference when using uv_timer_start and libuv

Meir Yanovich meiry242 at gmail.com
Tue Aug 2 15:17:51 CEST 2016


Hello
im trying to use uv_timer_start in the test-server-mirror.c , the timer
will triggered every
100 ms
to send the response back to the clients , the problem is how to get
the wsi of the current session
in the uv_timer_start callback

This is what i Intend to do :
i removed the from case LWS_CALLBACK_RECEIVE:
the call to lws_callback_on_writable_all_protocol as suggested by Andy and
moved it to the tmer callback


static void game_loop_cb(uv_timer_t* handle
#if UV_VERSION_MAJOR == 0
    , int status
#endif
    ) {

    ASSERT(handle != NULL);
    ASSERT(1 == uv_is_active((uv_handle_t*)handle));
    if (ringbuffer_head >-1)
    {
        if (((ringbuffer_head - pss->ringbuffer_tail) &
            (MAX_MESSAGE_QUEUE - 1)) != (MAX_MESSAGE_QUEUE - 2))
        {
            lws_callback_on_writable_all_protocol(lws_get_context(wsi),  //
<--- THIS IS THE problem how can i get the wsi of the current session ?
pointer what ? other lws method ?
                lws_get_protocol(wsi));
        }
    }

}



Thanks


case LWS_CALLBACK_PROTOCOL_INIT:
    {

        uv_timer_init(lws_uv_getloop(lws_get_context(wsi), 0),
&timeout_watcher);
        //every 100ms
        uv_timer_start(&timeout_watcher, game_loop_cb, 1000, 100);
        break;
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20160802/4a35a9bd/attachment.html>


More information about the Libwebsockets mailing list