[sr-dev] git:master: sercmd: read the rest from socket if message was too big for rcv buffer

Daniel-Constantin Mierla miconda at gmail.com
Fri Apr 18 17:30:10 CEST 2014


Module: sip-router
Branch: master
Commit: 5bc9e43eb6827220468f526c3df9d4c775311e51
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5bc9e43eb6827220468f526c3df9d4c775311e51

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at 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

---

 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);
 	




More information about the sr-dev mailing list