From fe7625d5da2ffaf4c34ae02394e53d044f9d3ab4 Mon Sep 17 00:00:00 2001 From: fumiama Date: Tue, 4 May 2021 14:11:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drecv=E8=BF=94=E5=9B=9E-1?= =?UTF-8?q?=E6=97=B6=E7=BA=BF=E7=A8=8B=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/server.c b/server.c index e1862ae..922f0da 100644 --- a/server.c +++ b/server.c @@ -269,10 +269,10 @@ void accept_timer(void *p) { THREADTIMER *timer = timerPointerOf(p); signal(SIGQUIT, handle_pipe); signal(SIGPIPE, handle_pipe); - while(!pthread_kill(*timer->thread, 0)) { + while(!pthread_kill(*(timer->thread), 0)) { sleep(MAXWAITSEC); puts("Check accept status"); - if(!*timer->thread) { + if(!*(timer->thread)) { free(timer); break; } else if(time(NULL) - timer->touch > MAXWAITSEC) { @@ -284,7 +284,7 @@ void accept_timer(void *p) { } void kill_thread(THREADTIMER* timer) { - pthread_kill(*timer->thread, SIGQUIT); + pthread_kill(*(timer->thread), SIGQUIT); close(timer->accept_fd); if(timer->data) { free(timer->data); @@ -296,12 +296,12 @@ void kill_thread(THREADTIMER* timer) { timer->is_open = 0; puts("Close file."); } - *timer->thread = 0; + *(timer->thread) = 0; puts("Kill thread."); } void handle_pipe(int signo) { - puts("Pipe error"); + printf("Pipe error: %d", signo); } void handle_accept(void *p) { @@ -319,7 +319,7 @@ void handle_accept(void *p) { char *buff = calloc(BUFSIZ, sizeof(char)); if(buff) { timerPointerOf(p)->data = buff; - while(*timerPointerOf(p)->thread && (timerPointerOf(p)->numbytes = recv(accept_fd, buff, BUFSIZ, 0)) > 0) { + while(*(timerPointerOf(p)->thread) && (timerPointerOf(p)->numbytes = recv(accept_fd, buff, BUFSIZ, 0)) > 0) { touchTimer(p); buff[timerPointerOf(p)->numbytes] = 0; printf("Get %zd bytes: %s\n", timerPointerOf(p)->numbytes, buff); @@ -327,9 +327,8 @@ void handle_accept(void *p) { if(!check_buffer(timerPointerOf(p))) break; } printf("Break: recv %zd bytes\n", timerPointerOf(p)->numbytes); - kill_thread(timerPointerOf(p)); } else puts("Error allocating buffer"); - close(accept_fd); + kill_thread(timerPointerOf(p)); } else puts("Error accepting client"); }