Created
January 12, 2015 10:25
-
-
Save ancuop/00e05a52497efee80d7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssize_t | |
lwan_writev(lwan_request_t *request, struct iovec *iov, int iov_count) { | |
ssize_t total_written = 0; | |
int curr_iov = 0; | |
/* Write header */ | |
ssize_t written = write(request->fd, iov[0].iov_base, iov[0].iov_len); | |
/* Write data */ | |
for (int tries = max_failed_tries; tries;) { | |
ssize_t written = write(request->fd, iov[1].iov_base, iov[1].iov_len); | |
if (UNLIKELY(written < 0)) { | |
/* FIXME: Consider short writes as another try as well? */ | |
tries--; | |
switch (errno) { | |
case EAGAIN: | |
case EINTR: | |
goto try_again; | |
default: | |
goto out; | |
} | |
} | |
total_written += written; | |
iov[1].iov_len -= (size_t) written; | |
if (iov[1].iov_len == 0) | |
return total_written; | |
iov[1].iov_base = (char *) iov[1].iov_base + written; | |
try_again: | |
coro_yield(request->conn->coro, CONN_CORO_MAY_RESUME); | |
} | |
out: | |
coro_yield(request->conn->coro, CONN_CORO_ABORT); | |
__builtin_unreachable(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment