From: Andre Noll Date: Sat, 2 Feb 2008 10:25:43 +0000 (+0100) Subject: http_send.c: Introduce http_write. X-Git-Tag: v0.3.1~64 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=57726462f32788fe818d96b9538d98d9598347db http_send.c: Introduce http_write. This allows to get rid of write_ok() and makes send_queued_chunks() identical to its counterpart in the dccp sender. --- diff --git a/error.h b/error.h index 9ef8195c..ece054b4 100644 --- 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 \ diff --git a/http_send.c b/http_send.c index 69e75ccb..ec7c5135 100644 --- a/http_send.c +++ b/http_send.c @@ -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;