aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/net.c14
-rw-r--r--src/net/lua.c24
-rw-r--r--src/net/lua.h1
-rw-r--r--src/test.c26
-rw-r--r--src/test.h3
-rw-r--r--tests/loc.lua15
6 files changed, 66 insertions, 17 deletions
diff --git a/src/net.c b/src/net.c
index b71b290..a356025 100644
--- a/src/net.c
+++ b/src/net.c
@@ -43,12 +43,12 @@ void* handle_client(void *_arg){
//read full request
//time_start(recv)
int64_t bytes_received = recv_full_buffer(client_fd, &buffer, &header_eof, &read_state);
- /*
- for(int i = 0; i != header_eof; i++)
+
+ /*for(int i = 0; i != header_eof; i++)
putchar(buffer[i]);
- putchar('\n');
- printf("hi %li:%i\n", bytes_received,header_eof);
- */
+ putchar('\n');*/
+ //printf("hi %li:%i\n", bytes_received,header_eof);
+
//ignore if header is just fucked
if(bytes_received >= -1){
parray_t* table;
@@ -104,12 +104,12 @@ void* handle_client(void *_arg){
//handle cookies
//TODO: enable and test with valgrind
- if(0 && sC != NULL){
+ if(sC != NULL){
lua_newtable(L);
int lcookie = lua_gettop(L);
parray_t* cookie = parray_init();
- //printf("%i\n",gen_parse(sC->c, sC->len, &cookie));
+ gen_parse(sC->c, sC->len, &cookie);
for(int i = 0; i != cookie->len; i++){
//printf("%s %s\n", cookie->P[i].key->c, ((str*)cookie->P[i].value)->c);
luaI_tsetsl(L, lcookie, cookie->P[i].key->c, ((str*)cookie->P[i].value)->c, ((str*)cookie->P[i].value)->len);
diff --git a/src/net/lua.c b/src/net/lua.c
index 2995326..9600189 100644
--- a/src/net/lua.c
+++ b/src/net/lua.c
@@ -182,7 +182,8 @@ int l_roll(lua_State* L){
return 1;
}
-#define bsize 512
+#define bsize 32768
+//#define bsize 12
int l_sendfile(lua_State* L){
int res_idx = 1;
@@ -206,20 +207,27 @@ int l_sendfile(lua_State* L){
p_fatal("missing permissions");
}
- str* r;
- i_write_header(L, header, &r, "", 0);
- send(client_fd, r->c, r->len, 0);
- str_free(r);
-
char* buffer = calloc(sizeof* buffer, bsize + 1);
FILE* fp = fopen(path, "rb");
fseek(fp, 0L, SEEK_END);
size_t sz = ftell(fp);
fseek(fp, 0L, SEEK_SET);
+
+ char size[256];
+ sprintf(size, "%li", sz);
+ luaI_tsets(L, header, "Content-Length", size);
+ //todo: allow file name
+ //luaI_tsets(L, header, "Content-Disposition", "attachment;");
+
+ str* r;
+ i_write_header(L, header, &r, "", 0);
+ send(client_fd, r->c, r->len, 0);
+ str_free(r);
- for(int i = 0; i < sz; i += bsize){
+ for(size_t i = 0; i < sz; i += bsize){
fread(buffer, sizeof * buffer, bsize, fp);
- send(client_fd, buffer, bsize > sz - i ? sz - i : bsize, 0);
+ if(send(client_fd, buffer, bsize > sz - i ? sz - i : bsize, 0) == -1)
+ break;
}
free(buffer);
diff --git a/src/net/lua.h b/src/net/lua.h
index 794e45f..d3c2371 100644
--- a/src/net/lua.h
+++ b/src/net/lua.h
@@ -4,5 +4,4 @@ int l_write(lua_State* L);
int l_send(lua_State* L);
int l_close(lua_State* L);
int l_roll(lua_State* L);
-#define bsize 512
int l_sendfile(lua_State* L);
diff --git a/src/test.c b/src/test.c
index 4408878..4b52753 100644
--- a/src/test.c
+++ b/src/test.c
@@ -23,3 +23,29 @@ int ld_match(lua_State* L){
return 2;
}
+int l_stack_dump(lua_State* L){
+ /*StkId a = L->top.p-2;
+ printf("%i %i\n", ttype(s2v(a)), LUA_TSTRING);
+ printf("is string? %i\n", ttisstring(&a->val));
+ printf("%s\n", tsvalue(&a->val)->contents);*/
+ //int level = 0;
+ //lua_lock(L);
+ //for(CallInfo* ci = L->ci; ci != &L->base_ci; ci = ci->previous) level++;
+ //lua_unlock(L);
+ //level -= 2;
+
+ //printf("%i\n", level);
+ lua_Debug info;
+ for(int i = 0; ; i++){
+ if(lua_getstack(L, i, &info) == 0) break;
+ for(int idx = 1;; idx++){
+ const char* name = lua_getlocal(L, &info, idx);
+ if(name == NULL) break;
+ printf("l:%i | %s = %s %s\n", i, name, lua_tostring(L, -1), lua_typename(L, lua_type(L, -1)));
+ lua_pop(L, 1);
+ }
+ }
+ //lua_getstack(L, level, &info);
+ //const char* name = lua_getlocal(L, &info, 2);
+ return 0;
+}
diff --git a/src/test.h b/src/test.h
index 01527c6..85c6b5b 100644
--- a/src/test.h
+++ b/src/test.h
@@ -1,9 +1,10 @@
#include "lua.h"
int ld_match(lua_State*);
+int l_stack_dump(lua_State*);
static const luaL_Reg test_function_list [] = {
{"_match", ld_match},
-
+ {"stack_dump", l_stack_dump},
{NULL,NULL}
};
diff --git a/tests/loc.lua b/tests/loc.lua
new file mode 100644
index 0000000..d50b9de
--- /dev/null
+++ b/tests/loc.lua
@@ -0,0 +1,15 @@
+llby = require "lullaby"
+
+local nya = "mya"
+uwu = "bye"
+local _o = _G
+_G.ooo = "mya"
+print(_o.ooo)
+local owo = "hi"
+
+function a()
+ local meo = "a"
+ llby.test.stack_dump()
+end
+
+a()