mirror of
https://github.com/fumiama/simple-kanban.git
synced 2026-06-30 08:00:27 +08:00
修复 粘连检测 sendfile尾指针未定义
This commit is contained in:
2
client.c
2
client.c
@@ -80,6 +80,8 @@ int main(int argc,char *argv[]) { //usage: ./client host port
|
|||||||
headers.iov_len = sizeof(uint32_t);
|
headers.iov_len = sizeof(uint32_t);
|
||||||
hdtr.headers = &headers;
|
hdtr.headers = &headers;
|
||||||
hdtr.hdr_cnt = 1;
|
hdtr.hdr_cnt = 1;
|
||||||
|
hdtr.trailers = NULL;
|
||||||
|
hdtr.trl_cnt = 0;
|
||||||
if(!sendfile(fileno(fp), sockfd, 0, &len, &hdtr, 0)) puts("Send file success.");
|
if(!sendfile(fileno(fp), sockfd, 0, &len, &hdtr, 0)) puts("Send file success.");
|
||||||
else puts("Send file error.");
|
else puts("Send file error.");
|
||||||
#else
|
#else
|
||||||
|
|||||||
29
server.c
29
server.c
@@ -127,7 +127,10 @@ int send_all(char* file_path, THREADTIMER *timer) {
|
|||||||
headers.iov_len = sizeof(uint32_t);
|
headers.iov_len = sizeof(uint32_t);
|
||||||
hdtr.headers = &headers;
|
hdtr.headers = &headers;
|
||||||
hdtr.hdr_cnt = 1;
|
hdtr.hdr_cnt = 1;
|
||||||
|
hdtr.trailers = NULL;
|
||||||
|
hdtr.trl_cnt = 0;
|
||||||
re = !sendfile(fileno(fp), timer->accept_fd, 0, &len, &hdtr, 0);
|
re = !sendfile(fileno(fp), timer->accept_fd, 0, &len, &hdtr, 0);
|
||||||
|
//if(!re) perror("Sendfile");
|
||||||
#else
|
#else
|
||||||
send(timer->accept_fd, &file_size, sizeof(uint32_t), 0);
|
send(timer->accept_fd, &file_size, sizeof(uint32_t), 0);
|
||||||
re = !sendfile(timer->accept_fd, fileno(fp), &len, file_size);
|
re = !sendfile(timer->accept_fd, fileno(fp), &len, file_size);
|
||||||
@@ -165,7 +168,11 @@ int s1_get(THREADTIMER *timer) { //get kanban
|
|||||||
close_file(fp);
|
close_file(fp);
|
||||||
timer->is_open = 0;
|
timer->is_open = 0;
|
||||||
int r = send_all(kanban_path, timer);
|
int r = send_all(kanban_path, timer);
|
||||||
if(strstr(timer->data, "quit") == timer->data - 4) return 0;
|
printf("Sendall returns %d\n", r);
|
||||||
|
if(strstr(timer->data, "quit") == timer->data - 4) {
|
||||||
|
puts("Found last cmd is quit.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
else return r;
|
else return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,7 +312,7 @@ void handle_pipe(int signo) {
|
|||||||
|
|
||||||
#define chkbuf(p) if(!check_buffer(timer_pointer_of(p))) break
|
#define chkbuf(p) if(!check_buffer(timer_pointer_of(p))) break
|
||||||
|
|
||||||
#define take_word(w) if(strstr(buff, w) == buff) {\
|
#define take_word(p, w) if(timer_pointer_of(p)->numbytes > strlen(w) && strstr(buff, w) == buff) {\
|
||||||
int l = strlen(w);\
|
int l = strlen(w);\
|
||||||
char store = buff[l];\
|
char store = buff[l];\
|
||||||
buff[l] = 0;\
|
buff[l] = 0;\
|
||||||
@@ -316,6 +323,7 @@ void handle_pipe(int signo) {
|
|||||||
memmove(buff + 1, buff + l + 1, n - 1);\
|
memmove(buff + 1, buff + l + 1, n - 1);\
|
||||||
buff[n] = 0;\
|
buff[n] = 0;\
|
||||||
timer_pointer_of(p)->numbytes = n;\
|
timer_pointer_of(p)->numbytes = n;\
|
||||||
|
printf("Split cmd: %s\n", w);\
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_accept(void *p) {
|
void handle_accept(void *p) {
|
||||||
@@ -338,15 +346,14 @@ void handle_accept(void *p) {
|
|||||||
buff[timer_pointer_of(p)->numbytes] = 0;
|
buff[timer_pointer_of(p)->numbytes] = 0;
|
||||||
printf("Get %zd bytes: %s\n", timer_pointer_of(p)->numbytes, buff);
|
printf("Get %zd bytes: %s\n", timer_pointer_of(p)->numbytes, buff);
|
||||||
puts("Check buffer");
|
puts("Check buffer");
|
||||||
if(timer_pointer_of(p)->numbytes > 3) { //处理部分粘连
|
//处理部分粘连
|
||||||
take_word(PASSWORD)
|
take_word(p, PASSWORD);
|
||||||
take_word("get")
|
take_word(p, "get");
|
||||||
take_word("cat")
|
take_word(p, "cat");
|
||||||
take_word("quit")
|
take_word(p, "quit");
|
||||||
take_word("set" SETPASS)
|
take_word(p, "set" SETPASS);
|
||||||
take_word("ver")
|
take_word(p, "ver");
|
||||||
take_word("dat")
|
take_word(p, "dat");
|
||||||
}
|
|
||||||
if(timer_pointer_of(p)->numbytes > 0) chkbuf(p);
|
if(timer_pointer_of(p)->numbytes > 0) chkbuf(p);
|
||||||
}
|
}
|
||||||
printf("Break: recv %zd bytes\n", timer_pointer_of(p)->numbytes);
|
printf("Break: recv %zd bytes\n", timer_pointer_of(p)->numbytes);
|
||||||
|
|||||||
Reference in New Issue
Block a user