Module: sip-router Branch: 4.1 Commit: ef31388e6654a6006d680fd1363f95ae6f1e2f80 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ef31388e...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Apr 18 17:22:43 2014 +0200
sercmd: read the rest from socket if message was too big for rcv buffer
- reported by Savolainen Dmitri, FS#422
(cherry picked from commit 5bc9e43eb6827220468f526c3df9d4c775311e51)
---
utils/sercmd/sercmd.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/utils/sercmd/sercmd.c b/utils/sercmd/sercmd.c index 7bb435a..a726eee 100644 --- a/utils/sercmd/sercmd.c +++ b/utils/sercmd/sercmd.c @@ -47,6 +47,7 @@ #include <netinet/in.h> /* udp sock */ #include <sys/uio.h> /* writev */ #include <netdb.h> /* gethostbyname */ +#include <fcntl.h> #include <time.h> /* time */
#ifdef USE_READLINE @@ -718,8 +719,14 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size, goto error; } msg_end=hdr_end+in_pkt->tlen; - if ((int)(msg_end-reply_buf)>max_reply_size) + if ((int)(msg_end-reply_buf)>max_reply_size) { + int flags = fcntl(s, F_GETFL, 0); + fcntl(s, F_SETFL, flags | O_NONBLOCK); + /* reading the rest from the socket */ + while(read(s, reply_buf, max_reply_size)>0); + fcntl(s, F_SETFL, flags & (~O_NONBLOCK)); goto error_toolong; + } } }while(crt<msg_end);