X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fclientsocket.c;h=3a3ac483eb7309ce4fa595f623b60ff8022ff0b5;hb=02862316ec5cf51e9153aef6c2e3622494735d3b;hp=7c69fe67333c93d3d82698f0291c3e078e667fb0;hpb=fdd218dbbc025b0b18e21ade3901c43f7365deeb;p=citadel.git diff --git a/citadel/clientsocket.c b/citadel/clientsocket.c index 7c69fe673..3a3ac483e 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -274,14 +274,19 @@ 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, char *buf, int nbytes) +int sock_write(int *sock, char *buf, int nbytes) { int bytes_written = 0; int retval; - while (bytes_written < nbytes) { - retval = write(sock, &buf[bytes_written], + + while ((*sock != -1) && + (bytes_written < nbytes)) + { + retval = write(*sock, &buf[bytes_written], nbytes - bytes_written); if (retval < 1) { + sock_close(*sock); + *sock = -1; return (-1); } bytes_written = bytes_written + retval; @@ -316,7 +321,7 @@ int ml_sock_gets(int *sock, char *buf) { * sock_puts() - send line to server - implemented in terms of serv_write() * Returns the number of bytes written, or -1 for error. */ -int sock_puts(int sock, char *buf) +int sock_puts(int *sock, char *buf) { int i, j;