From d65f43590ba5ff3dbe8c4d7728796a1e85236543 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 54bceb7a5..8052e24e4 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -231,7 +231,9 @@ INLINE int sock_read(int *sock, char *buf, int bytes, * 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; @@ -239,7 +241,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 ba5e35068..cb93d849b 100644 --- a/citadel/clientsocket.h +++ b/citadel/clientsocket.h @@ -22,6 +22,7 @@ int sock_connect(char *host, char *service); 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 4661c2f2f..7212731de 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -1268,7 +1268,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