Module: sip-router
Branch: 4.1
Commit: 080ad14a64834b7621bab3a0aa00e82d8de4490a
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=080ad14…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Apr 22 20:51:31 2014 +0200
sercmd: refactored reading the rest from socket on reply too long
- patch by by Savolainen Dmitri, FS#422
(cherry picked from commit fe9c519ca6ef6625f0b0d9c7027158641c636087)
---
utils/sercmd/sercmd.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/utils/sercmd/sercmd.c b/utils/sercmd/sercmd.c
index a726eee..00f10e7 100644
--- a/utils/sercmd/sercmd.c
+++ b/utils/sercmd/sercmd.c
@@ -720,11 +720,21 @@ static int get_reply(int s, unsigned char* reply_buf, int
max_reply_size,
}
msg_end=hdr_end+in_pkt->tlen;
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));
+ struct timeval timeout_save;
+ unsigned sizeoft = sizeof(timeout_save);
+ if (getsockopt(s, SOL_SOCKET, SO_RCVTIMEO,
+ &timeout_save, &sizeoft)==0) {
+ struct timeval timeout;
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+ if (setsockopt (s, SOL_SOCKET, SO_RCVTIMEO,
+ (char*)&timeout,sizeof(timeout))==0) {
+ while(read(s, reply_buf, max_reply_size)>0);
+ setsockopt(s, SOL_SOCKET, SO_RCVTIMEO,
+ (char*)&timeout_save,sizeof(timeout_save));
+ }
+ }
goto error_toolong;
}
}