make kore_websocket_send() slightly faster.

build the frame in a kore_buf on the stack and use net_send_stream()
to push it out rather then making yet another copy in net_send().

saves several cpu cycles before the frame starts going out as
we're not allocating a kore_buf, its contents and then memcpy()ing
that contents to a new netbuf.
This commit is contained in:
Joris Vink 2017-12-24 17:28:17 +01:00
parent fcc044af87
commit f8b3915ee1
1 changed files with 9 additions and 5 deletions

View File

@ -138,12 +138,16 @@ void
kore_websocket_send(struct connection *c, u_int8_t op, const void *data,
size_t len)
{
struct kore_buf *frame;
struct kore_buf frame;
frame = kore_buf_alloc(len);
websocket_frame_build(frame, op, data, len);
net_send_queue(c, frame->data, frame->offset);
kore_buf_free(frame);
kore_buf_init(&frame, len);
websocket_frame_build(&frame, op, data, len);
net_send_stream(c, frame.data, frame.offset, NULL, NULL);
/* net_send_stream() takes over the buffer data pointer. */
frame.data = NULL;
kore_buf_cleanup(&frame);
net_send_flush(c);
}