aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorame <[email protected]>2024-02-08 13:03:13 -0600
committerame <[email protected]>2024-02-08 13:03:13 -0600
commit6df5a49d612737784e824e91cac645447a3d3080 (patch)
treece915237c42ddd79014b668f11713d2ae2b1a677 /src/net.c
parent6c6146a89f5d4f2e615c8e97f26c896d50ff6d08 (diff)
globals mostly working
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/net.c b/src/net.c
index 5dde288..ccfa28c 100644
--- a/src/net.c
+++ b/src/net.c
@@ -338,8 +338,11 @@ int l_close(lua_State* L){
lua_pushstring(L, "client_fd");
lua_gettable(L, res_idx);
int client_fd = luaL_checkinteger(L, -1);
- if(client_fd <= 0) abort(); // add error message
-
+ if(client_fd <= 0){
+ printf("already closed\n");
+ abort();
+ }// add error message
+ return 0;
lua_pushstring(L, "client_fd");
lua_pushinteger(L, -1);
lua_settable(L, res_idx);
@@ -361,11 +364,15 @@ void* handle_client(void *_arg){
//create state for this thread
lua_State* L = luaL_newstate();
luaL_openlibs(L);
+
pthread_mutex_lock(&mutex);
+ int old_top = lua_gettop(args->L);
lua_getglobal(args->L, "_G");
i_dcopy(args->L, L, NULL);
+ lua_settop(args->L, old_top);
lua_setglobal(L, "_G");
pthread_mutex_unlock(&mutex);
+
//read full request
size_t bytes_received = recv_full_buffer(client_fd, &buffer, &header_eof);