aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorame <[email protected]>2024-01-23 14:13:45 -0600
committerame <[email protected]>2024-01-23 14:13:45 -0600
commit0fcff4f28f4b1f2493ecb17b3fac46bff8c8140c (patch)
tree0671f1abedab63573f3212d82d5c759b80c15422 /src/net.c
parent85c4718212e44b0e01485260b5f1574d5c7411a9 (diff)
almost working great, fix 35th con
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/net.c b/src/net.c
index 7beec3a..b0df7b9 100644
--- a/src/net.c
+++ b/src/net.c
@@ -22,7 +22,7 @@
#include "table.h"
#include "i_str.h"
-#define max_con 10
+#define max_con 200
#define BUFFER_SIZE 2048
static int ports[65535] = { 0 };
@@ -258,15 +258,15 @@ void* handle_client(void *_arg){
//str* resp;
//http_build(&resp, 200, "OK","text/html", "<h1>hello world!</h1>");
-
+
lua_State* L = args->L;
-
+
lua_rawgeti(L, LUA_REGISTRYINDEX, ports[args->port]);
int k = stable_key(table, "Path", len);
lua_pushstring(L, table[k]->c);
lua_gettable(L, -2);
- if(lua_type(L, -1) == LUA_TNIL){
+ if(1 || lua_type(L, -1) == LUA_TNIL){
str* resp;
http_build(&resp, 404, "Not Found","text/html", "<h1>404</h1>");
send(client_fd, resp->c, resp->len, 0);
@@ -327,6 +327,11 @@ void* handle_client(void *_arg){
//str_free(resp);
}
+
+ for(int i = 0; i != len; i++){
+ str_free(table[i]);
+ }
+ free(table);
}
closesocket(client_fd);
free(args);
@@ -352,7 +357,7 @@ void dcopy_lua(lua_State* dest, lua_State* src, int port){
lua_pushnil(src);
for(;lua_next(src,tt) != 0;){
char* key2 = (char*)luaL_checkstring(src, -2);
-
+
//copy function
lua_pushstring(dest, key2);
lua_xmove(src, dest, 1);
@@ -411,12 +416,9 @@ int start_serv(lua_State* L, int port){
abort();
}
- lua_State* oL = luaL_newstate();
-
- dcopy_lua(oL, L, port);
- //lua_rawgeti(oL, LUA_REGISTRYINDEX, ports[port]);
-
-
+ //open a state to call shit, should be somewhat thread safe
+ lua_State* oL = lua_newthread(L);
+ printf("%i\n",lua_gettop(L));
thread_arg_struct* args = malloc(sizeof * args);
args->fd = *client_fd;
args->port = port;