|
@@ -852,9 +852,7 @@ lwebsock_write(lua_State *L)
|
|
|
lua_gettable(L, LUA_REGISTRYINDEX);
|
|
|
ws = (struct lua_websock_data *)lua_touserdata(L, -1);
|
|
|
|
|
|
- printf("%p wwwww lock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_lock(&(ws->ws_mutex));
|
|
|
- printf("%p wwwww locked == %p)\n", pthread_self(), ws);
|
|
|
|
|
|
if (num_args == 1) {
|
|
|
/* just one text: send it to all client */
|
|
@@ -924,15 +922,11 @@ lwebsock_write(lua_State *L)
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- printf("%p wwwwwerr unlock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_unlock(&(ws->ws_mutex));
|
|
|
- printf("%p wwwwwerr unlocked == %p)\n", pthread_self(), ws);
|
|
|
return luaL_error(L, "invalid websocket write() call");
|
|
|
}
|
|
|
|
|
|
- printf("%p wwwww unlock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_unlock(&(ws->ws_mutex));
|
|
|
- printf("%p wwwww unlocked == %p)\n", pthread_self(), ws);
|
|
|
|
|
|
#else
|
|
|
(void)(L); /* unused */
|
|
@@ -953,9 +947,7 @@ lua_action(struct laction_arg *arg)
|
|
|
int err, ok;
|
|
|
struct mg_context *ctx;
|
|
|
|
|
|
- printf("%p action lock %p\n", pthread_self(), arg->pmutex);
|
|
|
(void)pthread_mutex_lock(arg->pmutex);
|
|
|
- printf("%p action locked %p\n", pthread_self(), arg->pmutex);
|
|
|
|
|
|
lua_pushlightuserdata(arg->state, (void *)&lua_regkey_ctx);
|
|
|
lua_gettable(arg->state, LUA_REGISTRYINDEX);
|
|
@@ -964,18 +956,14 @@ lua_action(struct laction_arg *arg)
|
|
|
err = luaL_loadstring(arg->state, arg->txt);
|
|
|
if (err != 0) {
|
|
|
lua_cry(fc(ctx), err, arg->state, arg->script, "timer");
|
|
|
- printf("%p action unlock1 %p\n", pthread_self(), arg->pmutex);
|
|
|
(void)pthread_mutex_unlock(arg->pmutex);
|
|
|
- printf("%p action unlocked1 %p\n", pthread_self(), arg->pmutex);
|
|
|
mg_free(arg);
|
|
|
return 0;
|
|
|
}
|
|
|
err = lua_pcall(arg->state, 0, 1, 0);
|
|
|
if (err != 0) {
|
|
|
lua_cry(fc(ctx), err, arg->state, arg->script, "timer");
|
|
|
- printf("%p action unlock2 %p\n", pthread_self(), arg->pmutex);
|
|
|
(void)pthread_mutex_unlock(arg->pmutex);
|
|
|
- printf("%p action unlocked2 %p\n", pthread_self(), arg->pmutex);
|
|
|
mg_free(arg);
|
|
|
return 0;
|
|
|
}
|
|
@@ -988,9 +976,7 @@ lua_action(struct laction_arg *arg)
|
|
|
}
|
|
|
lua_pop(arg->state, 1);
|
|
|
|
|
|
- printf("%p action unlockX %p\n", pthread_self(), arg->pmutex);
|
|
|
(void)pthread_mutex_unlock(arg->pmutex);
|
|
|
- printf("%p action unlockedX %p\n", pthread_self(), arg->pmutex);
|
|
|
|
|
|
if (!ok) {
|
|
|
mg_free(arg);
|
|
@@ -1236,15 +1222,12 @@ prepare_lua_environment(struct mg_context *ctx,
|
|
|
switch (lua_env_type) {
|
|
|
case LUA_ENV_TYPE_LUA_SERVER_PAGE:
|
|
|
reg_string(L, "lua_type", "page");
|
|
|
- printf("%p >Y>Y>Y page\n", pthread_self());
|
|
|
break;
|
|
|
case LUA_ENV_TYPE_PLAIN_LUA_PAGE:
|
|
|
reg_string(L, "lua_type", "script");
|
|
|
- printf("%p >Y>Y>Y script\n", pthread_self());
|
|
|
break;
|
|
|
case LUA_ENV_TYPE_LUA_WEBSOCKET:
|
|
|
reg_string(L, "lua_type", "websocket");
|
|
|
- printf("%p >Y>Y>Y websocket\n", pthread_self());
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -1498,11 +1481,6 @@ lua_websocket_new(const char *script, struct mg_connection *conn)
|
|
|
|
|
|
assert(conn->lua_websocket_state == NULL);
|
|
|
|
|
|
- printf("%p XXXXX lua_websocket_new(%s, %p)\n",
|
|
|
- pthread_self(),
|
|
|
- script,
|
|
|
- conn);
|
|
|
-
|
|
|
/* lock list (mg_context global) */
|
|
|
mg_lock_context(conn->ctx);
|
|
|
while (*shared_websock_list) {
|
|
@@ -1513,10 +1491,6 @@ lua_websocket_new(const char *script, struct mg_connection *conn)
|
|
|
shared_websock_list = &((*shared_websock_list)->next);
|
|
|
}
|
|
|
|
|
|
- printf("%p XXXXX shared_websock_list == %p)\n",
|
|
|
- pthread_self(),
|
|
|
- shared_websock_list);
|
|
|
-
|
|
|
if (*shared_websock_list == NULL) {
|
|
|
/* add ws to list */
|
|
|
*shared_websock_list = (struct mg_shared_lua_websocket_list *)
|
|
@@ -1530,9 +1504,7 @@ lua_websocket_new(const char *script, struct mg_connection *conn)
|
|
|
ws = &(*shared_websock_list)->ws;
|
|
|
ws->script = mg_strdup(script); /* TODO (low): handle OOM */
|
|
|
pthread_mutex_init(&(ws->ws_mutex), &pthread_mutex_attr);
|
|
|
- printf("%p XXXXX lock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_lock(&(ws->ws_mutex));
|
|
|
- printf("%p XXXXX locked == %p)\n", pthread_self(), ws);
|
|
|
ws->state = lua_newstate(lua_allocator, NULL);
|
|
|
ws->conn[0] = conn;
|
|
|
ws->references = 1;
|
|
@@ -1549,15 +1521,11 @@ lua_websocket_new(const char *script, struct mg_connection *conn)
|
|
|
} else {
|
|
|
/* inc ref count */
|
|
|
ws = &(*shared_websock_list)->ws;
|
|
|
- printf("%p XXXXX lock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_lock(&(ws->ws_mutex));
|
|
|
- printf("%p XXXXX locked == %p)\n", pthread_self(), ws);
|
|
|
(*shared_websock_list)->ws.conn[(ws->references)++] = conn;
|
|
|
}
|
|
|
mg_unlock_context(conn->ctx);
|
|
|
|
|
|
- printf("%p XXXXX ws == %p)\n", pthread_self(), ws);
|
|
|
-
|
|
|
/* call add */
|
|
|
lua_getglobal(ws->state, "open");
|
|
|
lua_newtable(ws->state);
|
|
@@ -1566,8 +1534,6 @@ lua_websocket_new(const char *script, struct mg_connection *conn)
|
|
|
lua_pushlightuserdata(ws->state, (void *)conn);
|
|
|
lua_rawset(ws->state, -3);
|
|
|
|
|
|
- printf("%p XXXXX lua_pcall == %p)\n", pthread_self(), ws->state);
|
|
|
-
|
|
|
err = lua_pcall(ws->state, 1, 1, 0);
|
|
|
if (err != 0) {
|
|
|
lua_cry(conn, err, ws->state, script, "open handler");
|
|
@@ -1584,9 +1550,7 @@ lua_websocket_new(const char *script, struct mg_connection *conn)
|
|
|
(*shared_websock_list)->ws.conn[--(ws->references)] = 0;
|
|
|
}
|
|
|
|
|
|
- printf("%p XXXXX unlock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_unlock(&(ws->ws_mutex));
|
|
|
- printf("%p XXXXX unlocked == %p)\n", pthread_self(), ws);
|
|
|
|
|
|
return ok ? (void *)ws : NULL;
|
|
|
}
|
|
@@ -1604,9 +1568,7 @@ lua_websocket_data(struct mg_connection *conn,
|
|
|
assert(ws != NULL);
|
|
|
assert(ws->state != NULL);
|
|
|
|
|
|
- printf("%p ddddd lock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_lock(&(ws->ws_mutex));
|
|
|
- printf("%p ddddd locked == %p)\n", pthread_self(), ws);
|
|
|
|
|
|
lua_getglobal(ws->state, "data");
|
|
|
lua_newtable(ws->state);
|
|
@@ -1632,9 +1594,7 @@ lua_websocket_data(struct mg_connection *conn,
|
|
|
}
|
|
|
lua_pop(ws->state, 1);
|
|
|
}
|
|
|
- printf("%p ddddd unlock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_unlock(&(ws->ws_mutex));
|
|
|
- printf("%p ddddd unlocked == %p)\n", pthread_self(), ws);
|
|
|
|
|
|
return ok;
|
|
|
}
|
|
@@ -1648,35 +1608,24 @@ lua_websocket_ready(struct mg_connection *conn, void *ws_arg)
|
|
|
assert(ws != NULL);
|
|
|
assert(ws->state != NULL);
|
|
|
|
|
|
- printf("%p rrrrr lock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_lock(&(ws->ws_mutex));
|
|
|
- printf("%p rrrrr locked == %p)\n", pthread_self(), ws);
|
|
|
|
|
|
lua_getglobal(ws->state, "ready");
|
|
|
lua_newtable(ws->state);
|
|
|
lua_pushstring(ws->state, "client");
|
|
|
lua_pushlightuserdata(ws->state, (void *)conn);
|
|
|
lua_rawset(ws->state, -3);
|
|
|
- printf("r2\n");
|
|
|
err = lua_pcall(ws->state, 1, 1, 0);
|
|
|
- printf("r3\n");
|
|
|
if (err != 0) {
|
|
|
- printf("r4\n");
|
|
|
lua_cry(conn, err, ws->state, ws->script, "ready handler");
|
|
|
- printf("r5\n");
|
|
|
} else {
|
|
|
- printf("r6\n");
|
|
|
if (lua_isboolean(ws->state, -1)) {
|
|
|
ok = lua_toboolean(ws->state, -1);
|
|
|
}
|
|
|
- printf("r7\n");
|
|
|
lua_pop(ws->state, 1);
|
|
|
- printf("r8\n");
|
|
|
}
|
|
|
|
|
|
- printf("%p rrrrr unlock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_unlock(&(ws->ws_mutex));
|
|
|
- printf("%p rrrrr unlocked == %p)\n", pthread_self(), ws);
|
|
|
|
|
|
return ok;
|
|
|
}
|
|
@@ -1693,9 +1642,7 @@ lua_websocket_close(struct mg_connection *conn, void *ws_arg)
|
|
|
assert(ws != NULL);
|
|
|
assert(ws->state != NULL);
|
|
|
|
|
|
- printf("%p ccccc lock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_lock(&(ws->ws_mutex));
|
|
|
- printf("%p ccccc locked == %p)\n", pthread_self(), ws);
|
|
|
|
|
|
lua_getglobal(ws->state, "close");
|
|
|
lua_newtable(ws->state);
|
|
@@ -1718,8 +1665,6 @@ lua_websocket_close(struct mg_connection *conn, void *ws_arg)
|
|
|
asynchronous operations and timers are completed/expired. */
|
|
|
(void)shared_websock_list; /* shared_websock_list unused (see open TODO) */
|
|
|
|
|
|
- printf("%p ccccc unlock == %p)\n", pthread_self(), ws);
|
|
|
(void)pthread_mutex_unlock(&(ws->ws_mutex));
|
|
|
- printf("%p ccccc unlocked == %p)\n", pthread_self(), ws);
|
|
|
}
|
|
|
#endif
|