1
0
mirror of https://github.com/wg/wrk synced 2025-02-13 14:13:14 +08:00

correctly handle partial writes

This commit is contained in:
Will 2013-06-21 12:31:05 +09:00
parent 6fd3ee1080
commit 87a5dae12c
2 changed files with 12 additions and 3 deletions

View File

@ -279,6 +279,7 @@ static int connect_socket(thread *thread, connection *c) {
http_parser_init(&c->parser, HTTP_RESPONSE);
c->parser.data = c;
c->fd = fd;
c->written = 0;
return fd;
@ -390,10 +391,17 @@ static int check_timeouts(aeEventLoop *loop, long long id, void *data) {
static void socket_writeable(aeEventLoop *loop, int fd, void *data, int mask) {
connection *c = data;
size_t len = req.size - c->written;
ssize_t n;
if (write(fd, req.buf, req.size) < req.size) goto error;
c->start = time_us();
aeDeleteFileEvent(loop, fd, AE_WRITABLE);
if ((n = write(fd, req.buf + c->written, len)) < 0) goto error;
if (!c->written) c->start = time_us();
c->written += n;
if (c->written == req.size) {
c->written = 0;
aeDeleteFileEvent(loop, fd, AE_WRITABLE);
}
return;

View File

@ -50,6 +50,7 @@ typedef struct connection {
http_parser parser;
int fd;
uint64_t start;
size_t written;
char buf[RECVBUF];
} connection;