unix: Don't malloc for each write
This commit is contained in:
parent
6c8d016fb4
commit
0bf38570e8
16
uv-unix.c
16
uv-unix.c
@ -659,7 +659,9 @@ static uv_req_t* uv__write(uv_tcp_t* tcp) {
|
||||
|
||||
/* Pop the req off tcp->write_queue. */
|
||||
ngx_queue_remove(&req->queue);
|
||||
free(req->bufs); /* FIXME: we should not be allocing for each read */
|
||||
if (req->bufs != req->bufsml) {
|
||||
free(req->bufs);
|
||||
}
|
||||
req->bufs = NULL;
|
||||
|
||||
/* Add it to the write_completed_queue where it will have its
|
||||
@ -973,11 +975,19 @@ int uv_write(uv_req_t* req, uv_buf_t bufs[], int bufcnt) {
|
||||
ngx_queue_init(&req->queue);
|
||||
req->type = UV_WRITE;
|
||||
|
||||
/* TODO: Don't malloc for each write... */
|
||||
req->bufs = malloc(sizeof(uv_buf_t) * bufcnt);
|
||||
|
||||
if (bufcnt < UV_REQ_BUFSML_SIZE) {
|
||||
req->bufs = req->bufsml;
|
||||
}
|
||||
else {
|
||||
req->bufs = malloc(sizeof(uv_buf_t) * bufcnt);
|
||||
}
|
||||
|
||||
memcpy(req->bufs, bufs, bufcnt * sizeof(uv_buf_t));
|
||||
req->bufcnt = bufcnt;
|
||||
|
||||
// fprintf(stderr, "cnt: %d bufs: %p bufsml: %p\n", bufcnt, req->bufs, req->bufsml);
|
||||
|
||||
req->write_index = 0;
|
||||
tcp->write_queue_size += uv__buf_count(bufs, bufcnt);
|
||||
|
||||
|
||||
@ -39,13 +39,15 @@ typedef struct {
|
||||
size_t len;
|
||||
} uv_buf_t;
|
||||
|
||||
#define UV_REQ_BUFSML_SIZE (4)
|
||||
|
||||
#define UV_REQ_PRIVATE_FIELDS \
|
||||
int write_index; \
|
||||
ev_timer timer; \
|
||||
ngx_queue_t queue; \
|
||||
uv_buf_t* bufs; \
|
||||
int bufcnt;
|
||||
int bufcnt; \
|
||||
uv_buf_t bufsml[UV_REQ_BUFSML_SIZE];
|
||||
|
||||
|
||||
/* TODO: union or classes please! */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user