Browse Source

A Redesign for Shared Websockets for Lua is Required

bel 11 years ago
parent
commit
9ae753eac5
2 changed files with 26 additions and 2 deletions
  1. 1 1
      src/civetweb.c
  2. 25 1
      src/mod_lua.inl

+ 1 - 1
src/civetweb.c

@@ -5093,7 +5093,7 @@ static void handle_websocket_request(struct mg_connection *conn, const char *pat
                                        path) : 0;
 
         if (lua_websock || shared_lua_websock) {
-            /* TODO */ shared_lua_websock = 1;
+            /* TODO */ shared_lua_websock = 0;
             conn->lua_websocket_state = lua_websocket_new(path, conn, !!shared_lua_websock);
             if (conn->lua_websocket_state) {
                 send_websocket_handshake(conn);

+ 25 - 1
src/mod_lua.inl

@@ -818,7 +818,7 @@ static int lua_error_handler(lua_State *L)
 }
 
 static void * lua_allocator(void *ud, void *ptr, size_t osize, size_t nsize) {
-  
+
     (void)ud; (void)osize; /* not used */
 
     if (nsize == 0) {
@@ -967,6 +967,15 @@ static void * lua_websocket_new(const char * script, struct mg_connection *conn,
 
     assert(conn->lua_websocket_state == NULL);
 
+    /*
+    lock
+    check if in list
+    yes: inc rec counter
+    no: create state, add to list
+    call add
+    unlock
+    */
+
     if (is_shared) {
         (void)pthread_mutex_lock(&conn->ctx->mutex);
         while (*shared_websock_list) {
@@ -1052,6 +1061,12 @@ static int lua_websocket_data(struct mg_connection *conn, int bits, char *data,
     assert(lws_data->main != NULL);
     assert(lws_data->thread != NULL);
 
+    /*
+    lock
+    call data
+    unlock
+    */
+
     do {
         retry=0;
 
@@ -1109,6 +1124,15 @@ static void lua_websocket_close(struct mg_connection *conn)
     assert(lws_data->main != NULL);
     assert(lws_data->thread != NULL);
 
+    /*
+    lock
+    call remove
+    dec ref counter
+    if ref counter == 0 close state and remove from list
+    unlock
+    */
+
+
     lua_pushboolean(lws_data->thread, 0);
     err = lua_resume(lws_data->thread, NULL, 1);