From 6707269817b5ecc5717d62c3ec806978171016e5 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 9 Apr 2017 15:22:53 +0200 Subject: core: Handle multiple lines in one tcp message --- main.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'main.c') 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; } -- cgit v1.2.3-54-g00ecf