From 3c4ea66b8b0b1269b3dd82382c389be9bad30ef7 Mon Sep 17 00:00:00 2001 From: mallocnull Date: Fri, 6 Oct 2017 21:01:06 +0000 Subject: [PATCH] private squids do not look --- src/.list.c.swp | Bin 16384 -> 0 bytes src/list.c | 19 +++++++++++++------ src/list.h | 3 +++ src/main.c | 3 --- src/server/server.c | 5 +++-- src/sock.c | 6 +++++- src/sock.h | 3 +++ src/stack.c | 4 ++-- src/stack.h | 4 ++-- 9 files changed, 31 insertions(+), 16 deletions(-) delete mode 100644 src/.list.c.swp diff --git a/src/.list.c.swp b/src/.list.c.swp deleted file mode 100644 index a4f3be2cc170750dc84646e542a81152504efd52..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI2Ym8h~9l%c!DO8GB0#W1R(%QN+-RVwwN!adaqNvrC5MwK}mSMVkhmLG#HZym+ z4Yu$>q=@1ps8kR?SbWe1!6PG-n#h{(fc-BWVp^YX3e*sxVpIV9p;~JGG=#eZmu=c?9R^?km< zeUIJey?y2GYyOd2Ah$qnf!qSQ1#%1I7RW7-TOhYUZh_naxdn0yybdi;n>FT4W*_adXBpiY-K>}C9;?&VXN?Wy}L`5blIq;AZ$dY=+C=Ja}oP zF;Bs7;MedV9ESVgAbbnH3D>}f;S#tQPK9R>_Gvf{55sq0FYJPyP=ib1TsX;Z7@mQr z;W#`5cf$f)2Q|1BE`fK$GWhEXbcSQ_ID8jwhHK$U_!w-4OW{0t3%qoOF;BoTI09X` z20j2|unyM3a`^k{#ykfn;FoX@+zJO^2W*FJP=>Xz4F0&>n4|DR_yODw2jCW1fG#93 z1sA|s@a$>E{2UI$eegB74Za9Bz+PB@X_$n!!`t95Z{#`n9()11kib>22_~TkWAI-1 z*Qv(*0Um&Za1-1JyWx8HEPN2og>zsPoZv9&_wX>>19!t+(1ooq4yVDNiAjme-}=KT z9Y2x3pYWwCOJsJ75?sl73U&w&PAbvfp-`blXj>-Hvy+_QY1gac84Wr~X>GJ(b!Tnn`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_tq)@J4Vfz+ih>7ic6Jsm)>iY~imS}(*Kr!cE+U3*^|K$4sv5Cd(!7U!QpyI6<3>y$K+0*mEBMYb`1t&(75**neifC z%2w|=H1$SBJlfZlcWA0s?Shp&$SLE1RfhQr^DGs(fz_3RT^t9gg&R3yhaS zC--2z-rEdkkD>afOzRvIWX(-@OvoGHCKu5$&zqw1j8S`sfYVIGHPQ{Jh kn9=)fejiPcs>QK6HWQwOxs_ndv+^|l*gOkGs}4OeqDxBvhE diff --git a/src/list.c b/src/list.c index de45d99..13c47e5 100644 --- a/src/list.c +++ b/src/list.c @@ -19,16 +19,15 @@ static list_node_t* list_node_init() { } static list_node_t* list_get_raw(list_t *list, int pos) { + if(pos >= list->size) + return NULL; + int i = 0; list_node_t *ptr = list->front; - for(i = 0; i < pos; ++i) { - if(i == pos) - return ptr; - + for(i = 0; i < pos; ++i) ptr = ptr->next; - } - return NULL; + return ptr; } static void list_add_first(list_t *list, void *data) { @@ -37,6 +36,7 @@ static void list_add_first(list_t *list, void *data) { list->front = list->back = list_node_init(); list->front->data = data; + list->size++; } void list_append(list_t *list, void *data) { @@ -169,6 +169,13 @@ void* list_iter_next(list_t *list) { return list->iterator == NULL ? NULL : list->iterator->data; } +void* list_iter_get(list_t *list) { + if(list->iterator == NULL) + return NULL; + + return list->iterator->data; +} + void* list_iter_remove(list_t *list) { if(list->iter_prev == NULL && list->iter_pos != 0) return NULL; diff --git a/src/list.h b/src/list.h index cfbe10c..a1172f8 100644 --- a/src/list.h +++ b/src/list.h @@ -32,6 +32,8 @@ void list_insert(list_t*, void*, int); int list_size(list_t*); void* list_get(list_t*, int); +void* list_front(list_t*); +void* list_back(list_t*); int list_find(list_t*, void*); int list_func_find(list_t*, listfindfptr); @@ -41,6 +43,7 @@ void* list_remove_back(list_t*); void list_iter_reset(list_t*); void* list_iter_next(list_t*); +void* list_iter_get(list_t*); void* list_iter_remove(list_t*); void list_iter_insert_before(list_t*, void*); void list_iter_insert_after(list_t*, void*); diff --git a/src/main.c b/src/main.c index 1cb7e48..907073e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,5 @@ #include "client/client.h" #include "server/server.h" -#include "stack.h" - -#include int main(int argc, char **argv) { if(argc == 2 && strcmp(argv[1], "server") == 0) { diff --git a/src/server/server.c b/src/server/server.c index e408606..c1364ec 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -4,8 +4,8 @@ void server() { socket_t *sock = sock_server_init("6770"); sock_start(sock); - sock_set_timeout(sock, 0, 1); - + sock_set_timeout_us(sock, 0, 100); + printf("awaiting connection...\r\n"); socket_t *conn = sock_accept(sock); @@ -22,3 +22,4 @@ void server() { sock_free(sock); } + diff --git a/src/sock.c b/src/sock.c index cad15ae..0bf46ca 100644 --- a/src/sock.c +++ b/src/sock.c @@ -83,9 +83,13 @@ int sock_start(socket_t *sock) { } void sock_set_timeout(socket_t *sock, int secs, int msecs) { + sock_set_timeout_us(sock, secs, msecs * 1000); +} + +void sock_set_timeout_us(socket_t *sock, int secs, int usecs) { struct timeval timeout; timeout.tv_sec = secs; - timeout.tv_usec = msecs * 1000; + timeout.tv_usec = usecs; setsockopt(sock->socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)); setsockopt(sock->socket, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof(timeout)); diff --git a/src/sock.h b/src/sock.h index 984a5c7..29a5fe4 100644 --- a/src/sock.h +++ b/src/sock.h @@ -43,7 +43,10 @@ socket_t* sock_server_init(char*); int sock_start(socket_t*); +// second int is millisecs void sock_set_timeout(socket_t*, int, int); +// second int is microsecs +void sock_set_timeout_us(socket_t*, int, int); void sock_set_blocking(socket_t*); void sock_set_nonblocking(socket_t*); BOOL sock_is_blocking(socket_t*); diff --git a/src/stack.c b/src/stack.c index e6d8e96..9fbdb64 100644 --- a/src/stack.c +++ b/src/stack.c @@ -40,7 +40,7 @@ void stack_free(stack_t *stack) { } } -void stack_node_free(stack_t *stack) { +void stack_nodes_free(stack_t *stack) { stack_t *ptr = stack, *next; while(ptr != NULL) { next = ptr->next; @@ -52,7 +52,7 @@ void stack_node_free(stack_t *stack) { } } -void stack_node_func_free(stack_t *stack, stackffptr ffptr) { +void stack_nodes_func_free(stack_t *stack, stackffptr ffptr) { stack_t *ptr = stack, *next; while(ptr != NULL) { next = ptr->next; diff --git a/src/stack.h b/src/stack.h index bdafec5..2c615b5 100644 --- a/src/stack.h +++ b/src/stack.h @@ -19,7 +19,7 @@ void* stack_pop(stack_t*); BOOL stack_can_pop(stack_t*); void stack_free(stack_t*); -void stack_node_free(stack_t*); -void stack_node_func_free(stack_t*, stackffptr); +void stack_nodes_free(stack_t*); +void stack_nodes_func_free(stack_t*, stackffptr); #endif