summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2014-03-14 09:53:29 +0100
committerYorhel <git@yorhel.nl>2014-03-14 09:53:29 +0100
commit6fff6607d36f3c912eadc2018f6c7de06d146343 (patch)
tree04d12784a0685c5b8f120b3a85b62baed5141972
parenteef584251db2a08eb897fc71b119ddaa3eff5de0 (diff)
net.c: Do lseek() before switching to non-sendfile fallback
We can't rely on sendfile() updating the file position.
-rw-r--r--src/net.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/net.c b/src/net.c
index cebf8e2..78579a3 100644
--- a/src/net.c
+++ b/src/net.c
@@ -408,8 +408,14 @@ static void syn_upload_sendfile(synfer_t *s, int sock, fadv_t *adv) {
} else if(errno == EAGAIN || errno == EINTR) {
continue;
} else if(errno == ENOTSUP || errno == ENOSYS || errno == EINVAL || errno == EOVERFLOW) {
- g_message("sendfile() failed with `%s', using fallback.", g_strerror(errno));
// Don't set s->err here, let the fallback handle the rest
+ g_message("sendfile() failed with `%s', using fallback.", g_strerror(errno));
+ // The fallback code continues from the fd position, so make sure to
+ // update it in case sendfile() didn't do so.
+ if(lseek(s->fd, off, SEEK_SET) == (off_t)-1) {
+ g_message("Can't switch to fallback, seek failed: %d (%s)", errno, g_strerror(errno));
+ s->err = g_strdup(g_strerror(errno));
+ }
return;
} else {
if(errno != EPIPE && errno != ECONNRESET)