Skip to content

Commit

Permalink
don't drop the chunk if it was only partially written
Browse files Browse the repository at this point in the history
update it instead while leaving it in the queue
  • Loading branch information
xant committed May 22, 2014
1 parent 8c12667 commit 9b42546
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/iomux.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ iomux_write_fd(iomux_t *iomux, int fd, void *priv)
return;
}

TAILQ_REMOVE(&iomux->connections[fd]->output_queue, chunk, next);
char *outbuf = chunk->data;
int outlen = chunk->len;

Expand All @@ -635,8 +634,17 @@ iomux_write_fd(iomux_t *iomux, int fd, void *priv)
}
} else {
MUTEX_LOCK(iomux);
iomux_output_chunk_t *next_chunk = TAILQ_FIRST(&iomux->connections[fd]->output_queue);
if (!next_chunk) {
outlen -= wb;
if (!outlen) {
TAILQ_REMOVE(&iomux->connections[fd]->output_queue, chunk, next);
if (chunk->free)
free(chunk->data);
free(chunk);
chunk = TAILQ_FIRST(&iomux->connections[fd]->output_queue);
} else {
memmove(chunk->data, chunk->data + wb, outlen);
}
if (!chunk) {
#if defined(HAVE_EPOLL)
// let's unregister this fd from EPOLLOUT events (seems nothing needs to be sent anymore)
struct epoll_event event = { 0 };
Expand All @@ -654,11 +662,6 @@ iomux_write_fd(iomux_t *iomux, int fd, void *priv)
}
MUTEX_UNLOCK(iomux);
}
if (chunk) {
if (chunk->free)
free(chunk->data);
free(chunk);
}
}

static struct timeval *
Expand Down

0 comments on commit 9b42546

Please sign in to comment.