#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 \
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;