diff options
-rw-r--r-- | src/sock.c | 32 | ||||
-rw-r--r-- | src/sock.h | 6 |
2 files changed, 27 insertions, 11 deletions
@@ -1,4 +1,4 @@ -/* $Id: sock.c,v 1.19 2001-12-15 05:58:30 rjkaes Exp $ +/* $Id: sock.c,v 1.20 2001-12-15 20:04:04 rjkaes Exp $ * * Sockets are created and destroyed here. When a new connection comes in from * a client, we need to copy the socket and the create a second socket to the @@ -271,18 +271,34 @@ getpeer_string(int fd, char *string) /* * Write the buffer to the socket. If an EINTR occurs, pick up and try - * again. + * again. Keep sending until the buffer has been sent. */ ssize_t -safe_write(int fd, const void *buffer, size_t count) +safe_write(int fd, const char *buffer, size_t count) { ssize_t len; + size_t bytestosend; - do { - len = write(fd, buffer, count); - } while (len < 0 && errno == EINTR); + bytestosend = count; - return len; + while (1) { + len = write(fd, buffer, bytestosend); + + if (len < 0) { + if (errno == EINTR) + continue; + else + return -errno; + } + + if (len == bytestosend) + break; + + buffer += len; + bytestosend -= len; + } + + return count; } /* @@ -290,7 +306,7 @@ safe_write(int fd, const void *buffer, size_t count) * again. */ ssize_t -safe_read(int fd, void *buffer, size_t count) +safe_read(int fd, char *buffer, size_t count) { ssize_t len; @@ -1,4 +1,4 @@ -/* $Id: sock.h,v 1.7 2001-11-22 00:19:18 rjkaes Exp $ +/* $Id: sock.h,v 1.8 2001-12-15 20:04:04 rjkaes Exp $ * * See 'sock.c' for a detailed description. * @@ -35,8 +35,8 @@ extern int socket_blocking(int sock); extern char *getpeer_ip(int fd, char *ipaddr); extern char *getpeer_string(int fd, char *string); -extern ssize_t safe_write(int fd, const void *buffer, size_t count); -extern ssize_t safe_read(int fd, void *buffer, size_t count); +extern ssize_t safe_write(int fd, const char *buffer, size_t count); +extern ssize_t safe_read(int fd, char *buffer, size_t count); extern ssize_t readline(int fd, char **whole_buffer); |