diff options
| author | amelia squires <[email protected]> | 2024-09-11 00:02:08 -0500 |
|---|---|---|
| committer | amelia squires <[email protected]> | 2024-09-11 00:02:08 -0500 |
| commit | f776ebf34442e0ac6dfc46afd5ac47793db82ac3 (patch) | |
| tree | 25f1642859355d7cbe82a8b57549c2d2f52f8dbe /src/net.c | |
| parent | e9cb2e0f75cbfa6bde188b9e043ebfd8d30b9451 (diff) | |
add res:stop
Diffstat (limited to 'src/net.c')
| -rw-r--r-- | src/net.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -161,6 +161,8 @@ void* handle_client(void *_arg){ luaI_tsetcf(L, res_idx, "sendfile", l_sendfile);
luaI_tsetcf(L, res_idx, "write", l_write);
luaI_tsetcf(L, res_idx, "close", l_close);
+ luaI_tsetcf(L, res_idx, "stop", l_stop);
+
//values
luaI_tseti(L, res_idx, "client_fd", client_fd);
@@ -210,10 +212,18 @@ void* handle_client(void *_arg){ //call the function
lua_call(L, 2, 0);
+
+ //check if res:stop() was called
+ lua_pushstring(L, "_stop");
+ lua_gettable(L, res_idx);
+ if(!lua_isnil(L, -1))
+ goto net_end;
}
}
}
+
+net_end:
larray_clear(params);
parray_lclear(owo); //dont free the rest
@@ -289,6 +299,7 @@ int start_serv(lua_State* L, int port){ if (pthread_mutex_init(&con_mutex, NULL) != 0)
p_fatal("con_mutex init failed\n");
+ int count = 0;
for(;;){
struct sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
@@ -297,6 +308,13 @@ int start_serv(lua_State* L, int port){ if((*client_fd = accept(server_fd, (struct sockaddr*)&client_addr, &client_addr_len)) < 0)
p_fatal("failed to accept\n");
+ if(count >= max_con){
+ //deny request
+ free(client_fd);
+ continue;
+ }
+ count++;
+
//open a state to call shit, should be somewhat thread safe
thread_arg_struct* args = malloc(sizeof * args);
|
