From ecdc9e87a3ac4a50299291550c775cfcca783f34 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Mon, 13 Dec 2010 18:23:31 +0100 Subject: [PATCH] SMTP Async I/O: - while sending data, wait relative to the size of the mail /128 + a minimal set of 50. --- citadel/clientsocket.c | 5 +++-- citadel/clientsocket.h | 1 + citadel/modules/smtp/serv_smtp.c | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/citadel/clientsocket.c b/citadel/clientsocket.c index 91094aa8a..572f28f17 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -264,7 +264,9 @@ INLINE int sock_read(int *sock, char *buf, int bytes, int keep_reading_until_ful * sock_write() - send binary to server. * Returns the number of bytes written, or -1 for error. */ -int sock_write(int *sock, const char *buf, int nbytes) +int sock_write(int *sock, const char *buf, int nbytes) +{ return sock_write_timeout(sock, buf, nbytes, 50); } +int sock_write_timeout(int *sock, const char *buf, int nbytes, int timeout) { int nSuccessLess = 0; int bytes_written = 0; @@ -272,7 +274,6 @@ int sock_write(int *sock, const char *buf, int nbytes) fd_set rfds; int fdflags; int IsNonBlock; - int timeout = 50; struct timeval tv; int selectresolution = 100; diff --git a/citadel/clientsocket.h b/citadel/clientsocket.h index 491d7e3b1..69898156d 100644 --- a/citadel/clientsocket.h +++ b/citadel/clientsocket.h @@ -24,6 +24,7 @@ int sock_connect(char *host, char *service, char *protocol); int sock_read_to(int *sock, char *buf, int bytes, int timeout, int keep_reading_until_full); int sock_read(int *sock, char *buf, int bytes, int keep_reading_until_full); int sock_write(int *sock, const char *buf, int nbytes); +int sock_write_timeout(int *sock, const char *buf, int nbytes, int timeout); int ml_sock_gets(int *sock, char *buf, int nSec); int sock_getln(int *sock, char *buf, int bufsize); int CtdlSockGetLine(int *sock, StrBuf *Target, int nSec); diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index b0572f5a1..fc43a9624 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -1272,7 +1272,10 @@ void smtp_try(const char *key, const char *addr, int *status, } /* If we reach this point, the server is expecting data.*/ - sock_write(&sock, msgtext, msg_size); + sock_write_timeout(&sock, + msgtext, + msg_size, + (msg_size / 128) + 50); if (msgtext[msg_size-1] != 10) { CtdlLogPrintf(CTDL_WARNING, "Possible problem: message did not " "correctly terminate. (expecting 0x10, got 0x%02x)\n", -- 2.30.2