From: Art Cancro Date: Wed, 22 Dec 2010 04:35:03 +0000 (-0500) Subject: Revert "Replaced client_read() with socket_read_blob() in serv_network.c" X-Git-Tag: v8.01~498 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=49982a083283668bcdc6852390f2f746bc44c220;p=citadel.git Revert "Replaced client_read() with socket_read_blob() in serv_network.c" This reverts commit f4fcd4228633ddd1334f24f0a572d0667215082f. --- diff --git a/citadel/clientsocket.c b/citadel/clientsocket.c index 594b5eb96..8052e24e4 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -147,6 +147,28 @@ int socket_read_blob(int *Socket, StrBuf * Target, int bytes, int timeout) } +int sock_read_to(int *sock, char *buf, int bytes, int timeout, + int keep_reading_until_full) +{ + CitContext *CCC = MyContext(); + int rc; + + FlushStrBuf(CCC->MigrateBuf); + rc = socket_read_blob(sock, CCC->sMigrateBuf, bytes, timeout); + if (rc < 0) { + *buf = '\0'; + return rc; + } else { + if (StrLength(CCC->MigrateBuf) < bytes) + bytes = StrLength(CCC->MigrateBuf); + memcpy(buf, ChrPtr(CCC->MigrateBuf), bytes); + + FlushStrBuf(CCC->MigrateBuf); + return rc; + } +} + + int CtdlSockGetLine(int *sock, StrBuf * Target, int nSec) { CitContext *CCC = MyContext(); @@ -193,6 +215,18 @@ int sock_getln(int *sock, char *buf, int bufsize) } +/* + * sock_read() - input binary data from socket. + * Returns the number of bytes read, or -1 for error. + */ +INLINE int sock_read(int *sock, char *buf, int bytes, + int keep_reading_until_full) +{ + return sock_read_to(sock, buf, bytes, CLIENT_TIMEOUT, + keep_reading_until_full); +} + + /* * sock_write() - send binary to server. * Returns the number of bytes written, or -1 for error. diff --git a/citadel/clientsocket.h b/citadel/clientsocket.h index c430c1882..cb93d849b 100644 --- a/citadel/clientsocket.h +++ b/citadel/clientsocket.h @@ -19,13 +19,14 @@ */ 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); int sock_puts(int *sock, char *buf); -int socket_read_blob(int *Socket, StrBuf * Target, int bytes, int timeout); /* diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index 075b4578a..7f5d5dd30 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -1924,6 +1924,7 @@ void receive_spool(int *sock, char *remote_nodename) { int download_len = 0L; int bytes_received = 0L; char buf[SIZ]; + static char pbuf[IGNET_PACKET_SIZE]; char tempfilename[PATH_MAX]; char permfilename[PATH_MAX]; int plen; @@ -1997,17 +1998,13 @@ void receive_spool(int *sock, char *remote_nodename) { if (buf[0] == '6') { plen = extract_int(&buf[4], 0); - StrBuf *pbuf = NewStrBuf(); - if (socket_read_blob(sock, pbuf, plen, CLIENT_TIMEOUT) != plen) { - CtdlLogPrintf(CTDL_INFO, "Short read from peer; aborting.\n"); + if (sock_read(sock, pbuf, plen, 1) < 0) { fclose(fp); unlink(tempfilename); - FreeStrBuf(&pbuf); return; } - fwrite(ChrPtr(pbuf), plen, 1, fp); + fwrite((char *) pbuf, plen, 1, fp); bytes_received += plen; - FreeStrBuf(&pbuf); } } @@ -2034,6 +2031,7 @@ void receive_spool(int *sock, char *remote_nodename) { } CtdlLogPrintf(CTDL_DEBUG, "%s\n", buf); + CtdlLogPrintf(CTDL_NOTICE, "Received %ld octets from <%s>\n", download_len, remote_nodename); /* * Now move the temp file to its permanent location.