X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2FClientSocket.c;h=ad634dc4408388a28fa301de24d5c7bb17e8c2ab;hb=a0f5e337ee57df78939e9ddaccf9a18bcf811435;hp=80f4c37d2cae7f73fa4cdd4b996858bfa528d551;hpb=64122d18ddffb83f70192a1036c4fc601485a0cd;p=NeonServV5.git diff --git a/src/ClientSocket.c b/src/ClientSocket.c index 80f4c37..ad634dc 100644 --- a/src/ClientSocket.c +++ b/src/ClientSocket.c @@ -33,6 +33,12 @@ struct socket_list { #ifdef HAVE_THREADS static pthread_mutex_t synchronized; static pthread_mutex_t synchronized_recv; + +struct ParseOrder { + unsigned int tid; + struct ParseOrder *next; +}; +struct ParseOrder *parse_order = NULL; #endif //the magic list :P @@ -224,7 +230,7 @@ static int _connect_socket(struct ClientSocket *client) { return 1; } #else -static int connect_socket(struct ClientSocket *client) { +static int _connect_socket(struct ClientSocket *client) { if((client->flags & SOCKET_FLAG_CONNECTED)) return 1; struct hostent *host; struct sockaddr_in addr; @@ -369,8 +375,51 @@ int write_socket(struct ClientSocket *client, char* msg, int len) { return write_socket_force(client, msg, len); } -void socket_loop(int timeout_seconds) { - if(sockets == NULL) return; +#if HAVE_THREADS +static void clientsocket_start_of_recv(unsigned int tid) { + SYNCHRONIZE(whohandler_sync); + struct ParseOrder *entry, *last; + for(last = parse_order; last; last = last->next) { + if(last->next == NULL) + break; + } + entry = malloc(sizeof(*entry)); + entry->tid = tid; + entry->next = NULL; + if(last) + last->next = entry; + else + parse_order = entry; + DESYNCHRONIZE(whohandler_sync); +} + +static void clientsocket_end_of_recv(unsigned int tid) { + SYNCHRONIZE(whohandler_sync); + struct ParseOrder *entry, *last = NULL; + for(entry = parse_order; entry; entry = entry->next) { + if(entry->tid == tid) { + if(last) + last->next = entry->next; + else + parse_order = entry->next; + free(entry); + break; + } else + last = entry; + } + DESYNCHRONIZE(whohandler_sync); +} + +int clientsocket_parseorder_top(unsigned int tid) { + if(parse_order && parse_order->tid == tid) + return 1; + else + return 0; +} +#endif + +int socket_loop(int timeout_seconds) { + if(sockets == NULL) return 0; int is_synchronized = 1; SYNCHRONIZE(synchronized_recv); fd_set fds; @@ -390,7 +439,7 @@ void socket_loop(int timeout_seconds) { ret = select(ret + 1, &fds, NULL, NULL, &timeout); if(ret == 0) { DESYNCHRONIZE(synchronized_recv); - return; + return 1; } for (sock = sockets->data; sock; sock = next) { next = sock->next; @@ -445,11 +494,11 @@ void socket_loop(int timeout_seconds) { sock->bufferpos -= used; } is_synchronized = 0; - unsigned long tid = syscall(SYS_gettid); - whohandler_start_of_recv(sock, tid); + unsigned int tid = (unsigned int) pthread_self_tid(); + clientsocket_start_of_recv(tid); DESYNCHRONIZE(synchronized_recv); parse_lines(sock, linesbuf, used); - whohandler_end_of_recv(sock, tid); //WHOHandler hack (unlock WHOQueue mutexes) + clientsocket_end_of_recv(tid); #else int used = parse_lines(sock, sock->buffer, sock->bufferpos); if(used == sock->bufferpos + 1) { @@ -481,6 +530,7 @@ void socket_loop(int timeout_seconds) { if(is_synchronized) { DESYNCHRONIZE(synchronized_recv); } + return (ret + 1); } void