introduce this param in callback fix server close on client socket
authorAndy Green <andy@warmcat.com>
Mon, 14 Feb 2011 09:14:25 +0000 (09:14 +0000)
committerAndy Green <andy@warmcat.com>
Mon, 14 Feb 2011 09:14:25 +0000 (09:14 +0000)
Signed-off-by: Andy Green <andy@warmcat.com>
lib/client-handshake.c
lib/handshake.c
lib/libwebsockets.c
lib/libwebsockets.h
lib/parsers.c
libwebsockets-api-doc.html
test-server/test-client.c
test-server/test-ping.c
test-server/test-server-extpoll.c
test-server/test-server.c

index e219450..df91923 100644 (file)
@@ -498,7 +498,7 @@ check_accept:
        this->fds[this->fds_count++].events = POLLIN;
 
        /* external POLL support via protocol 0 */
-       this->protocols[0].callback(wsi,
+       this->protocols[0].callback(this, wsi,
                LWS_CALLBACK_ADD_POLL_FD,
                (void *)(long)wsi->sock, NULL, POLLIN);
 
@@ -510,7 +510,7 @@ check_accept:
 
        /* call him back to inform him he is up */
 
-       wsi->protocol->callback(wsi,
+       wsi->protocol->callback(this, wsi,
                         LWS_CALLBACK_CLIENT_ESTABLISHED,
                         wsi->user_space,
                         NULL, 0);
index 1ba4b92..90219a2 100644 (file)
@@ -208,7 +208,8 @@ handshake_00(struct libwebsocket *wsi)
        /* notify user code that we're ready to roll */
 
        if (wsi->protocol->callback)
-               wsi->protocol->callback(wsi, LWS_CALLBACK_ESTABLISHED,
+               wsi->protocol->callback(wsi->protocol->owning_server,
+                               wsi, LWS_CALLBACK_ESTABLISHED,
                                          wsi->user_space, NULL, 0);
 
        return 0;
@@ -398,7 +399,8 @@ handshake_0405(struct libwebsocket *wsi)
        /* notify user code that we're ready to roll */
 
        if (wsi->protocol->callback)
-               wsi->protocol->callback(wsi, LWS_CALLBACK_ESTABLISHED,
+               wsi->protocol->callback(wsi->protocol->owning_server,
+                               wsi, LWS_CALLBACK_ESTABLISHED,
                                          wsi->user_space, NULL, 0);
 
        return 0;
@@ -484,7 +486,7 @@ libwebsocket_read(struct libwebsocket_context *this, struct libwebsocket *wsi,
                if (!wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len ||
                             !wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len) {
                        if (wsi->protocol->callback)
-                               (wsi->protocol->callback)(wsi,
+                               (wsi->protocol->callback)(this, wsi,
                                   LWS_CALLBACK_HTTP, wsi->user_space,
                                   wsi->utf8_token[WSI_TOKEN_GET_URI].token, 0);
                        wsi->state = WSI_STATE_HTTP;
@@ -538,7 +540,7 @@ libwebsocket_read(struct libwebsocket_context *this, struct libwebsocket *wsi,
                 * have the opportunity to deny it
                 */
 
-               if ((wsi->protocol->callback)(wsi,
+               if ((wsi->protocol->callback)(wsi->protocol->owning_server, wsi,
                                LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION,
                                                &wsi->utf8_token[0], NULL, 0)) {
                        fprintf(stderr, "User code denied connection\n");
index d4db3f3..ec1e482 100644 (file)
@@ -80,15 +80,16 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *this,
                                                       struct libwebsocket *wsi)
 {
        int n;
+       int old_state;
        unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2 +
                                                  LWS_SEND_BUFFER_POST_PADDING];
 
        if (!wsi)
                return;
 
-       n = wsi->state;
+       old_state = wsi->state;
 
-       if (n == WSI_STATE_DEAD_SOCKET)
+       if (old_state == WSI_STATE_DEAD_SOCKET)
                return;
 
        /* remove this fd from wsi mapping hashtable */
@@ -111,7 +112,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *this,
 
        /* remove also from external POLL support via protocol 0 */
 
-       this->protocols[0].callback(wsi,
+       this->protocols[0].callback(this, wsi,
                    LWS_CALLBACK_DEL_POLL_FD, (void *)(long)wsi->sock, NULL, 0);
 
        /*
@@ -122,7 +123,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *this,
         * WSI_STATE_RETURNED_CLOSE_ALREADY and we will skip this
         */
 
-       if (n == WSI_STATE_ESTABLISHED)
+       if (old_state == WSI_STATE_ESTABLISHED)
                libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 0,
                                                               LWS_WRITE_CLOSE);
 
@@ -130,8 +131,8 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *this,
 
        /* tell the user it's all over for this guy */
 
-       if (wsi->protocol->callback && n == WSI_STATE_ESTABLISHED)
-               wsi->protocol->callback(wsi, LWS_CALLBACK_CLOSED,
+       if (wsi->protocol->callback && old_state == WSI_STATE_ESTABLISHED)
+               wsi->protocol->callback(this, wsi, LWS_CALLBACK_CLOSED,
                                                      wsi->user_space, NULL, 0);
 
        /* free up his allocations */
@@ -317,7 +318,7 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
                 * yet so we issue this to protocols[0]
                 */
 
-               if ((this->protocols[0].callback)(wsi,
+               if ((this->protocols[0].callback)(this, wsi,
                                LWS_CALLBACK_FILTER_NETWORK_CONNECTION,
                                             (void*)(long)accept_fd, NULL, 0)) {
                        fprintf(stderr, "Callback denied network connection\n");
@@ -420,7 +421,7 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
                this->fds[this->fds_count++].fd = accept_fd;
 
                /* external POLL support via protocol 0 */
-               this->protocols[0].callback(new_wsi,
+               this->protocols[0].callback(this, new_wsi,
                        LWS_CALLBACK_ADD_POLL_FD,
                        (void *)(long)accept_fd, NULL, POLLIN);
 
@@ -469,7 +470,7 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
                this->fds[this->fds_count++].fd = accept_fd;
 
                /* external POLL support via protocol 0 */
-               this->protocols[0].callback(new_wsi,
+               this->protocols[0].callback(this, new_wsi,
                        LWS_CALLBACK_ADD_POLL_FD,
                        (void *)(long)accept_fd, NULL, POLLIN);
 
@@ -497,11 +498,11 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
                        pollfd->events &= ~POLLOUT;
 
                        /* external POLL support via protocol 0 */
-                       this->protocols[0].callback(wsi,
+                       this->protocols[0].callback(this, wsi,
                                LWS_CALLBACK_CLEAR_MODE_POLL_FD,
                                (void *)(long)wsi->sock, NULL, POLLOUT);
 
-                       wsi->protocol->callback(wsi,
+                       wsi->protocol->callback(this, wsi,
                                LWS_CALLBACK_CLIENT_WRITEABLE,
                                wsi->user_space,
                                NULL, 0);
@@ -553,7 +554,7 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
 
                                /* broadcast it to this connection */
 
-                               new_wsi->protocol->callback(new_wsi,
+                               new_wsi->protocol->callback(this, new_wsi,
                                        LWS_CALLBACK_BROADCAST,
                                        new_wsi->user_space,
                                        buf + LWS_SEND_BUFFER_PRE_PADDING, len);
@@ -568,7 +569,7 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
 
                if (pollfd->revents & (POLLERR | POLLHUP)) {
 
-                       debug("Session Socket %p (fd=%d) dead\n",
+                       fprintf(stderr, "Session Socket %p (fd=%d) dead\n",
                                (void *)wsi, pollfd->fd);
 
                        libwebsocket_close_and_free_session(this, wsi);
@@ -582,11 +583,11 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
                        pollfd->events &= ~POLLOUT;
 
                        /* external POLL support via protocol 0 */
-                       this->protocols[0].callback(wsi,
+                       this->protocols[0].callback(this, wsi,
                                LWS_CALLBACK_CLEAR_MODE_POLL_FD,
                                (void *)(long)wsi->sock, NULL, POLLOUT);
 
-                       wsi->protocol->callback(wsi,
+                       wsi->protocol->callback(this, wsi,
                                LWS_CALLBACK_CLIENT_WRITEABLE,
                                wsi->user_space,
                                NULL, 0);
@@ -713,7 +714,7 @@ libwebsocket_service(struct libwebsocket_context *this, int timeout_ms)
        if (n == 0) /* poll timeout */
                return 0;
 
-       if (n < 0 || this->fds[0].revents & (POLLERR | POLLHUP)) {
+       if (n < 0) {
                /*
                fprintf(stderr, "Listen Socket dead\n");
                */
@@ -738,9 +739,9 @@ libwebsocket_service(struct libwebsocket_context *this, int timeout_ms)
  */
 
 int
-libwebsocket_callback_on_writable(struct libwebsocket *wsi)
+libwebsocket_callback_on_writable(struct libwebsocket_context *this,
+                                                      struct libwebsocket *wsi)
 {
-       struct libwebsocket_context *this = wsi->protocol->owning_server;
        int n;
 
        for (n = 0; n < this->fds_count; n++)
@@ -750,7 +751,7 @@ libwebsocket_callback_on_writable(struct libwebsocket *wsi)
                }
 
        /* external POLL support via protocol 0 */
-       this->protocols[0].callback(wsi,
+       this->protocols[0].callback(this, wsi,
                LWS_CALLBACK_SET_MODE_POLL_FD,
                (void *)(long)wsi->sock, NULL, POLLOUT);
 
@@ -782,7 +783,7 @@ libwebsocket_callback_on_writable_all_protocol(
                        wsi = this->fd_hashtable[n].wsi[m];
 
                        if (wsi->protocol == protocol)
-                               libwebsocket_callback_on_writable(wsi);
+                               libwebsocket_callback_on_writable(this, wsi);
                }
        }
 
@@ -833,12 +834,12 @@ libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable)
 
        if (enable)
                /* external POLL support via protocol 0 */
-               this->protocols[0].callback(wsi,
+               this->protocols[0].callback(this, wsi,
                        LWS_CALLBACK_SET_MODE_POLL_FD,
                        (void *)(long)wsi->sock, NULL, POLLIN);
        else
                /* external POLL support via protocol 0 */
-               this->protocols[0].callback(wsi,
+               this->protocols[0].callback(this, wsi,
                        LWS_CALLBACK_CLEAR_MODE_POLL_FD,
                        (void *)(long)wsi->sock, NULL, POLLIN);
 
@@ -1154,7 +1155,7 @@ libwebsocket_create_context(int port,
                this->fds[this->fds_count++].events = POLLIN;
 
                /* external POLL support via protocol 0 */
-               this->protocols[0].callback(wsi,
+               this->protocols[0].callback(this, wsi,
                        LWS_CALLBACK_ADD_POLL_FD,
                        (void *)(long)sockfd, NULL, POLLIN);
 
@@ -1232,7 +1233,7 @@ libwebsocket_create_context(int port,
                this->fds_count++;
 
                /* external POLL support via protocol 0 */
-               this->protocols[0].callback(wsi,
+               this->protocols[0].callback(this, wsi,
                        LWS_CALLBACK_ADD_POLL_FD,
                        (void *)(long)fd, NULL, POLLIN);
        }
@@ -1395,7 +1396,7 @@ libwebsockets_broadcast(const struct libwebsocket_protocols *protocol,
                                if (wsi->protocol != protocol)
                                        continue;
 
-                               wsi->protocol->callback(wsi,
+                               wsi->protocol->callback(this, wsi,
                                         LWS_CALLBACK_BROADCAST,
                                         wsi->user_space,
                                         buf, len);
index 5a65c21..7b73a6b 100644 (file)
@@ -125,6 +125,7 @@ struct libwebsocket_context;
 /* document the generic callback (it's a fake prototype under this) */
 /**
  * callback() - User server actions
+ * @this:      Websockets context
  * @wsi:       Opaque websocket instance pointer
  * @reason:    The reason for the call
  * @user:      Pointer to per-session user data allocated by library
@@ -235,7 +236,8 @@ struct libwebsocket_context;
  *             pollfd struct for this socket descriptor.  If you are using the
  *             internal polling loop, you can just ignore it.
  */
-extern int callback(struct libwebsocket *wsi,
+extern int callback(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                         enum libwebsocket_callback_reasons reason, void *user,
                                                          void *in, size_t len);
 
@@ -269,7 +271,8 @@ extern int callback(struct libwebsocket *wsi,
 
 struct libwebsocket_protocols {
        const char *name;
-       int (*callback)(struct libwebsocket *wsi,
+       int (*callback)(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                        enum libwebsocket_callback_reasons reason, void *user,
                                                          void *in, size_t len);
        size_t per_session_data_size;
@@ -352,7 +355,8 @@ extern const struct libwebsocket_protocols *
 libwebsockets_get_protocol(struct libwebsocket *wsi);
 
 extern int
-libwebsocket_callback_on_writable(struct libwebsocket *wsi);
+libwebsocket_callback_on_writable(struct libwebsocket_context *this,
+                                                     struct libwebsocket *wsi);
 
 extern int
 libwebsocket_callback_on_writable_all_protocol(
index e095b06..d6cae1c 100644 (file)
@@ -128,10 +128,10 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
                /* no payload challenge in 01 + */
 
                if (wsi->utf8_token[WSI_TOKEN_VERSION].token_len &&
-                        atoi(wsi->utf8_token[WSI_TOKEN_VERSION].token) > 0) {
-                       wsi->utf8_token[wsi->parser_state].token_len = 0;
-                       free(wsi->utf8_token[wsi->parser_state].token);
-                       wsi->utf8_token[wsi->parser_state].token = NULL;
+                          atoi(wsi->utf8_token[WSI_TOKEN_VERSION].token) > 0) {
+                       wsi->utf8_token[WSI_TOKEN_CHALLENGE].token_len = 0;
+                       free(wsi->utf8_token[WSI_TOKEN_CHALLENGE].token);
+                       wsi->utf8_token[WSI_TOKEN_CHALLENGE].token = NULL;
                }
 
                /* For any supported protocol we have enough payload */
@@ -555,7 +555,8 @@ post_mask:
                        break;
 issue:
                if (wsi->protocol->callback)
-                       wsi->protocol->callback(wsi, LWS_CALLBACK_RECEIVE,
+                       wsi->protocol->callback(wsi->protocol->owning_server,
+                         wsi, LWS_CALLBACK_RECEIVE,
                          wsi->user_space,
                          &wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
                          wsi->rx_user_buffer_head);
@@ -642,7 +643,8 @@ spill:
                                               wsi->rx_user_buffer_head] = '\0';
 
                if (wsi->protocol->callback)
-                       wsi->protocol->callback(wsi, LWS_CALLBACK_RECEIVE,
+                       wsi->protocol->callback(wsi->protocol->owning_server,
+                                               wsi, LWS_CALLBACK_RECEIVE,
                                                wsi->user_space,
                          &wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
                                                      wsi->rx_user_buffer_head);
@@ -880,7 +882,8 @@ int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
                        break;
 issue:
                if (wsi->protocol->callback)
-                       wsi->protocol->callback(wsi,
+                       wsi->protocol->callback(wsi->protocol->owning_server,
+                                               wsi,
                                                LWS_CALLBACK_CLIENT_RECEIVE,
                                                wsi->user_space,
                          &wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
@@ -958,7 +961,8 @@ spill:
                 */
 
                if (wsi->protocol->callback)
-                       wsi->protocol->callback(wsi, callback_action,
+                       wsi->protocol->callback(wsi->protocol->owning_server,
+                                               wsi, callback_action,
                                                wsi->user_space,
                          &wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
                                                      wsi->rx_user_buffer_head);
index 1415ff5..3f080b2 100644 (file)
@@ -123,7 +123,8 @@ nothing is pending, or as soon as it services whatever was pending.
 <h2>libwebsocket_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking *</h2>
 <i>int</i>
 <b>libwebsocket_callback_on_writable</b>
-(<i>struct libwebsocket *</i> <b>wsi</b>)
+(<i>struct libwebsocket_context *</i> <b>this</b>,
+<i>struct libwebsocket *</i> <b>wsi</b>)
 <h3>Arguments</h3>
 <dl>
 <dt><b>wsi</b>
@@ -439,13 +440,16 @@ This function creates a connection to a remote server
 <h2>callback - User server actions</h2>
 <i>int</i>
 <b>callback</b>
-(<i>struct libwebsocket *</i> <b>wsi</b>,
+(<i>struct libwebsocket_context *</i> <b>this</b>,
+<i>struct libwebsocket *</i> <b>wsi</b>,
 <i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
 <i>void *</i> <b>user</b>,
 <i>void *</i> <b>in</b>,
 <i>size_t</i> <b>len</b>)
 <h3>Arguments</h3>
 <dl>
+<dt><b>this</b>
+<dd>Websockets context
 <dt><b>wsi</b>
 <dd>Opaque websocket instance pointer
 <dt><b>reason</b>
@@ -600,7 +604,7 @@ internal polling loop, you can just ignore it.
 <h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
 <b>struct libwebsocket_protocols</b> {<br>
 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
-&nbsp; &nbsp; <i>int (*</i><b>callback</b>) <i>(struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)</i>;<br>
+&nbsp; &nbsp; <i>int (*</i><b>callback</b>) <i>(struct libwebsocket_context * this,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)</i>;<br>
 &nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
 &nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
 &nbsp; &nbsp; <i>int</i> <b>broadcast_socket_port</b>;<br>
index 298d013..52ce477 100644 (file)
@@ -56,7 +56,8 @@ enum demo_protocols {
 /* dumb_increment protocol */
 
 static int
-callback_dumb_increment(struct libwebsocket *wsi,
+callback_dumb_increment(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                        enum libwebsocket_callback_reasons reason,
                                               void *user, void *in, size_t len)
 {
@@ -79,7 +80,8 @@ callback_dumb_increment(struct libwebsocket *wsi,
 
 
 static int
-callback_lws_mirror(struct libwebsocket *wsi,
+callback_lws_mirror(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                        enum libwebsocket_callback_reasons reason,
                                               void *user, void *in, size_t len)
 {
@@ -96,7 +98,7 @@ callback_lws_mirror(struct libwebsocket *wsi,
                 * LWS_CALLBACK_CLIENT_WRITEABLE will come next service
                 */
 
-               libwebsocket_callback_on_writable(wsi);
+               libwebsocket_callback_on_writable(this, wsi);
                break;
 
        case LWS_CALLBACK_CLIENT_RECEIVE:
@@ -117,7 +119,7 @@ callback_lws_mirror(struct libwebsocket *wsi,
 
                /* get notified as soon as we can write again */
 
-               libwebsocket_callback_on_writable(wsi);
+               libwebsocket_callback_on_writable(this, wsi);
 
                /*
                 * without at least this delay, we choke the browser
index 8703a41..c04bb87 100644 (file)
@@ -46,6 +46,7 @@
 #define MAX_PING_CLIENTS 256
 #define PING_RINGBUFFER_SIZE 256
 
+static struct libwebsocket *ping_wsi[MAX_PING_CLIENTS];
 static unsigned int interval_us = 1000000;
 static unsigned int size = 64;
 static int flood;
@@ -97,7 +98,8 @@ enum demo_protocols {
 
 
 static int
-callback_lws_mirror(struct libwebsocket *wsi,
+callback_lws_mirror(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                        enum libwebsocket_callback_reasons reason,
                                               void *user, void *in, size_t len)
 {
@@ -111,6 +113,23 @@ callback_lws_mirror(struct libwebsocket *wsi,
        struct per_session_data__ping *psd = user;
 
        switch (reason) {
+       case LWS_CALLBACK_CLOSED:
+
+               fprintf(stderr, "LWS_CALLBACK_CLOSED on %p\n", (void *)wsi);
+
+               /* remove closed guy */
+       
+               for (n = 0; n < clients; n++)
+                       if (ping_wsi[n] == wsi) {                               
+                               clients--;
+                               while (n < clients) {
+                                       ping_wsi[n] = ping_wsi[n + 1];
+                                       n++;
+                               }
+                       }
+
+               break;
+
        case LWS_CALLBACK_CLIENT_ESTABLISHED:
 
                psd->rx_count = 0;
@@ -123,7 +142,7 @@ callback_lws_mirror(struct libwebsocket *wsi,
                 * LWS_CALLBACK_CLIENT_WRITEABLE will come next service
                 */
 
-               libwebsocket_callback_on_writable(wsi);
+               libwebsocket_callback_on_writable(this, wsi);
                break;
 
        case LWS_CALLBACK_CLIENT_RECEIVE:
@@ -298,7 +317,6 @@ int main(int argc, char **argv)
        int port = 7681;
        int use_ssl = 0;
        struct libwebsocket_context *context;
-       struct libwebsocket *wsi[MAX_PING_CLIENTS];
        char protocol_name[256];
        char ip[30];
        struct sigaction sa;
@@ -392,18 +410,19 @@ int main(int argc, char **argv)
        /* create client websockets using dumb increment protocol */
 
        for (n = 0; n < clients; n++) {
-               wsi[n] = libwebsocket_client_connect(context, address, port,
-                                                    use_ssl, "/", address,
+               ping_wsi[n] = libwebsocket_client_connect(context, address,
+                                                  port, use_ssl, "/", address,
                                 "origin", protocols[PROTOCOL_LWS_MIRROR].name,
                                                                  ietf_version);
-               if (wsi[n] == NULL) {
+               if (ping_wsi[n] == NULL) {
                        fprintf(stderr, "client connnection %d failed to "
                                                                "connect\n", n);
                        return 1;
                }
        }
 
-       libwebsockets_get_peer_addresses(libwebsocket_get_socket_fd(wsi[0]),
+       libwebsockets_get_peer_addresses(
+                       libwebsocket_get_socket_fd(ping_wsi[0]),
                                    peer_name, sizeof peer_name, ip, sizeof ip);
 
        fprintf(stderr, "Websocket PING %s (%s) %d bytes of data.\n",
@@ -427,12 +446,18 @@ int main(int argc, char **argv)
                gettimeofday(&tv, NULL);
                l = (tv.tv_sec * 1000000) + tv.tv_usec;
 
+               /* servers can hang up on us */
+
+               if (clients == 0) {
+                       n = -1;
+                       continue;
+               }
 
                if (!interrupted_time) {
                        if ((l - oldus) > interval_us) {
                                for (n = 0; n < clients; n++)
                                        libwebsocket_callback_on_writable(
-                                                                       wsi[n]);
+                                                         context, ping_wsi[n]);
                                oldus = l;
                        }
                } else
index 450e5f6..74b1c02 100644 (file)
@@ -72,7 +72,8 @@ enum demo_protocols {
 
 /* this protocol server (always the first one) just knows how to do HTTP */
 
-static int callback_http(struct libwebsocket *wsi,
+static int callback_http(struct libwebsocket_context * this,
+               struct libwebsocket *wsi,
                enum libwebsocket_callback_reasons reason, void *user,
                                                           void *in, size_t len)
 {
@@ -216,7 +217,8 @@ struct per_session_data__dumb_increment {
 };
 
 static int
-callback_dumb_increment(struct libwebsocket *wsi,
+callback_dumb_increment(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                        enum libwebsocket_callback_reasons reason,
                                               void *user, void *in, size_t len)
 {
@@ -293,7 +295,8 @@ static int ringbuffer_head;
 
 
 static int
-callback_lws_mirror(struct libwebsocket *wsi,
+callback_lws_mirror(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                        enum libwebsocket_callback_reasons reason,
                                               void *user, void *in, size_t len)
 {
@@ -305,7 +308,7 @@ callback_lws_mirror(struct libwebsocket *wsi,
        case LWS_CALLBACK_ESTABLISHED:
                pss->ringbuffer_tail = ringbuffer_head;
                pss->wsi = wsi;
-               libwebsocket_callback_on_writable(wsi);
+               libwebsocket_callback_on_writable(this, wsi);
                break;
 
        case LWS_CALLBACK_CLIENT_WRITEABLE:
@@ -332,7 +335,7 @@ callback_lws_mirror(struct libwebsocket *wsi,
                                  MAX_MESSAGE_QUEUE) < (MAX_MESSAGE_QUEUE - 15))
                                libwebsocket_rx_flow_control(wsi, 1);
 
-                       libwebsocket_callback_on_writable(wsi);
+                       libwebsocket_callback_on_writable(this, wsi);
 
                }
                break;
index 9143c03..db22868 100644 (file)
@@ -60,7 +60,8 @@ enum demo_protocols {
 
 /* this protocol server (always the first one) just knows how to do HTTP */
 
-static int callback_http(struct libwebsocket *wsi,
+static int callback_http(struct libwebsocket_context * this,
+               struct libwebsocket *wsi,
                enum libwebsocket_callback_reasons reason, void *user,
                                                           void *in, size_t len)
 {
@@ -171,7 +172,8 @@ struct per_session_data__dumb_increment {
 };
 
 static int
-callback_dumb_increment(struct libwebsocket *wsi,
+callback_dumb_increment(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                        enum libwebsocket_callback_reasons reason,
                                               void *user, void *in, size_t len)
 {
@@ -247,7 +249,8 @@ static int ringbuffer_head;
 
 
 static int
-callback_lws_mirror(struct libwebsocket *wsi,
+callback_lws_mirror(struct libwebsocket_context * this,
+                       struct libwebsocket *wsi,
                        enum libwebsocket_callback_reasons reason,
                                               void *user, void *in, size_t len)
 {
@@ -283,7 +286,7 @@ callback_lws_mirror(struct libwebsocket *wsi,
                                  MAX_MESSAGE_QUEUE) < (MAX_MESSAGE_QUEUE - 15))
                                libwebsocket_rx_flow_control(wsi, 1);
 
-                       libwebsocket_callback_on_writable(wsi);
+                       libwebsocket_callback_on_writable(this, wsi);
 
                }
                break;