From 475b96db0a345a354785b76e65a691572f2d207e Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 1 Dec 2001 19:23:27 +0000 Subject: [PATCH] * clientsocket.c: implement socket timeouts for read operations --- citadel/ChangeLog | 4 +++- citadel/clientsocket.c | 47 +++++++++++++++++++++++++++++++++++------- citadel/clientsocket.h | 6 ++++++ citadel/sysdep.c | 2 +- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 559e733df..f5512c297 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 580.83 2001/12/01 19:23:26 ajc + * clientsocket.c: implement socket timeouts for read operations + Revision 580.82 2001/12/01 17:00:23 ajc * serv_smtp.c: when multiple MX's are the same preference, randomize them @@ -2889,4 +2892,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/clientsocket.c b/citadel/clientsocket.c index f096cdb34..b1ad7f05e 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include "snprintf.h" #endif #include "sysdep_decls.h" +#include #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff @@ -91,23 +93,52 @@ int sock_connect(char *host, char *service, char *protocol) return (s); } + + /* - * sock_read() - input binary data from socket. + * sock_read_to() - input binary data from socket, with a settable timeout. * Returns the number of bytes read, or -1 for error. */ -int sock_read(int sock, char *buf, int bytes) +int sock_read_to(int sock, char *buf, int bytes, int timeout) { - int len, rlen; + int len,rlen; + fd_set rfds; + struct timeval tv; + int retval; len = 0; - while (len < bytes) { - rlen = read(sock, &buf[len], bytes - len); - if (rlen < 1) { - return (-1); + while(len