kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit f8b3915ee13e63e169fc75ce98995c1b1f6d5808
parent fcc044af879e77a235eaba0f4535f95a3f35d3e3
Author: Joris Vink <joris@coders.se>
Date:   Sun, 24 Dec 2017 17:28:17 +0100

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.

Diffstat:
src/websocket.c | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/websocket.c b/src/websocket.c @@ -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); }