]> git.tue.mpg.de Git - paraslash.git/commitdiff
http_send.c: Introduce http_write.
authorAndre Noll <maan@systemlinux.org>
Sat, 2 Feb 2008 10:25:43 +0000 (11:25 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 2 Feb 2008 10:25:43 +0000 (11:25 +0100)
This allows to get rid of write_ok() and makes
send_queued_chunks() identical to its counterpart
in the dccp sender.

error.h
http_send.c

diff --git a/error.h b/error.h
index 9ef8195c1f6af10a43e1f58d32a5d292152f7f51..ece054b49d295488a7fdb1a01bf633533043586e 100644 (file)
--- a/error.h
+++ b/error.h
@@ -318,7 +318,6 @@ extern const char **para_errlist[];
 
 #define HTTP_SEND_ERRORS \
        PARA_ERROR(WRITE_OK, "can not check whether fd is writable"), \
-       PARA_ERROR(SEND_QUEUED_CHUNK, "failed to send queued chunk"), \
 
 
 #define COMMAND_ERRORS \
index 69e75ccb80eddd0badfdf49aadaadcf6e75e8417..ec7c51355fdfad5b695b6a9b2c9a941801cc4570 100644 (file)
@@ -116,19 +116,37 @@ static int http_send_err_msg(struct http_client *hc)
        return http_send_msg(hc, HTTP_ERR_MSG);
 }
 
+/*
+ * ret: Negative on errors, zero if nothing was written and write returned
+ * EAGAIN, number of bytes written else.
+ */
+static int http_write(int fd, const char *buf, size_t len)
+{
+       size_t written = 0;
+
+       while (written < len) {
+               int ret = write(fd, buf + written, len - written);
+               if (ret < 0 && errno == EAGAIN)
+                       return written;
+               if (ret < 0)
+                       return -ERRNO_TO_PARA_ERROR(errno);
+               written += ret;
+       }
+       return written;
+}
+
+
 static int send_queued_chunks(struct http_client *hc)
 {
        struct queued_chunk *qc;
        while ((qc = cq_peek(hc->cq))) {
                char *buf;
                size_t len;
-               int ret = write_ok(hc->fd);
-               if (ret <= 0)
-                       return ret? -E_WRITE_OK : 0;
+               int ret;
                cq_get(qc, &buf, &len);
-               ret = write(hc->fd, buf, len);
+               ret = http_write(hc->fd, buf, len);
                if (ret < 0)
-                       return -E_SEND_QUEUED_CHUNK;
+                       return ret;
                cq_update(hc->cq, ret);
                if (ret != len)
                        return 1;