From c6b1981c9c6380613abbf1e02b7a48af4b3fccbc Mon Sep 17 00:00:00 2001 From: fumiama Date: Wed, 5 May 2021 21:29:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=B9=E5=88=A4=E5=A4=84=E7=90=86=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E7=B2=98=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/server.c b/server.c index 1eca817..69e3753 100644 --- a/server.c +++ b/server.c @@ -164,7 +164,9 @@ int s1_get(THREADTIMER *timer) { //get kanban if(cli_ver < ver) { //need to send a new kanban close_file(fp); timer->is_open = 0; - return send_all(kanban_path, timer); + int r = send_all(kanban_path, timer); + if(strstr(timer->data, "quit") == timer->data - 4) return 0; + else return r; } } } @@ -301,6 +303,21 @@ void handle_pipe(int signo) { printf("Pipe error: %d\n", signo); } +#define chkbuf(p) if(!check_buffer(timer_pointer_of(p))) break + +#define take_word(w) if(strstr(buff, w) == buff) {\ + int l = strlen(w);\ + char store = buff[l];\ + buff[l] = 0;\ + ssize_t n = timer_pointer_of(p)->numbytes - l;\ + timer_pointer_of(p)->numbytes = l;\ + chkbuf(p);\ + buff[0] = store;\ + memmove(buff + 1, buff + l + 1, n - 1);\ + buff[n] = 0;\ + timer_pointer_of(p)->numbytes = n;\ + } + void handle_accept(void *p) { pthread_detach(pthread_self()); int accept_fd = timer_pointer_of(p)->accept_fd; @@ -321,7 +338,16 @@ void handle_accept(void *p) { buff[timer_pointer_of(p)->numbytes] = 0; printf("Get %zd bytes: %s\n", timer_pointer_of(p)->numbytes, buff); puts("Check buffer"); - if(!check_buffer(timer_pointer_of(p))) break; + if(timer_pointer_of(p)->numbytes > 3) { //处理部分粘连 + take_word(PASSWORD) + take_word("get") + take_word("cat") + take_word("quit") + take_word("set" SETPASS) + take_word("ver") + take_word("dat") + } + if(timer_pointer_of(p)->numbytes > 0) chkbuf(p); } printf("Break: recv %zd bytes\n", timer_pointer_of(p)->numbytes); } else puts("Error allocating buffer");