aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-04-09 15:22:53 +0200
committertomsmeding <tom.smeding@gmail.com>2017-04-09 15:22:53 +0200
commit6707269817b5ecc5717d62c3ec806978171016e5 (patch)
treeb305a6ee3f46d4159de23ea7aa26f85ef6131585
parentd241509b8f925c9424b677c51f454b7dedaa8dd2 (diff)
core: Handle multiple lines in one tcp message
-rw-r--r--main.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/main.c b/main.c
index aa0fdc5..1a0bd10 100644
--- a/main.c
+++ b/main.c
@@ -89,17 +89,19 @@ static bool client_socket_callback(int fd){
}
data->buflen+=ret;
- char *lfp=memchr(data->buffer,'\n',data->buflen);
- if(lfp==NULL)return false;
- size_t length=lfp-data->buffer;
- bool should_close=handle_input_line(data,data->buffer,length);
- memmove(data->buffer,lfp+1,data->buflen-length-1);
- data->buflen-=length+1;
-
- if(should_close){
- delete_conn_data(fd);
- close(fd);
- return true;
+ while(true){
+ char *lfp=memchr(data->buffer,'\n',data->buflen);
+ if(lfp==NULL)break;
+ size_t length=lfp-data->buffer;
+ bool should_close=handle_input_line(data,data->buffer,length);
+ memmove(data->buffer,lfp+1,data->buflen-length-1);
+ data->buflen-=length+1;
+
+ if(should_close){
+ delete_conn_data(fd);
+ close(fd);
+ return true;
+ }
}
return false;
}