summaryrefslogtreecommitdiff
path: root/src/sock.c
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2001-12-15 20:04:04 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2001-12-15 20:04:04 +0000
commitb969ed430228ffc2300c2aa1eb1356a362171302 (patch)
tree7d8cc2f9e6a1fb413e94799f9b5eb7025e2b49f8 /src/sock.c
parentcad9a5d11b2e1034135123c0936c24303f674bc6 (diff)
downloadtinyproxy-b969ed430228ffc2300c2aa1eb1356a362171302.tar.gz
tinyproxy-b969ed430228ffc2300c2aa1eb1356a362171302.zip
Changed safe_write() to fully send all the data in the buffer it was
passed. Also safe_write() and safe_read() now use char pointer buffers rather than the void pointer style.
Diffstat (limited to '')
-rw-r--r--src/sock.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/sock.c b/src/sock.c
index fd071d7..67825b9 100644
--- a/src/sock.c
+++ b/src/sock.c
@@ -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;