diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-04-09 15:22:53 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-04-09 15:22:53 +0200 |
commit | 6707269817b5ecc5717d62c3ec806978171016e5 (patch) | |
tree | b305a6ee3f46d4159de23ea7aa26f85ef6131585 | |
parent | d241509b8f925c9424b677c51f454b7dedaa8dd2 (diff) |
core: Handle multiple lines in one tcp message
-rw-r--r-- | main.c | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -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; } |