private squids do not look

This commit is contained in:
mallocnull 2017-10-06 21:01:06 +00:00
parent f74c7c4488
commit 3c4ea66b8b
9 changed files with 31 additions and 16 deletions

Binary file not shown.

View file

@ -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;

View file

@ -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*);

View file

@ -1,8 +1,5 @@
#include "client/client.h"
#include "server/server.h"
#include "stack.h"
#include <stdio.h>
int main(int argc, char **argv) {
if(argc == 2 && strcmp(argv[1], "server") == 0) {

View file

@ -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);
}

View file

@ -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));

View file

@ -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*);

View file

@ -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;

View file

@ -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