diff --git a/src/.list.c.swp b/src/.list.c.swp deleted file mode 100644 index a4f3be2..0000000 Binary files a/src/.list.c.swp and /dev/null differ 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