From a2306f3b2d82aacc350aa5f5f0a20b45a25b0cd0 Mon Sep 17 00:00:00 2001 From: Andrei Vaduva Date: Fri, 13 Sep 2019 12:11:05 +0300 Subject: [PATCH] Added setNoDelay function --- lib/connection.js | 8 ++++++++ src/turbo_net.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/connection.js b/lib/connection.js index f443a1c..10f3c48 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -16,6 +16,7 @@ class Connection extends events.EventEmitter { this.allowHalfOpen = false this.writable = false this.readable = false + this.noDelay = false; this._index = 0 // used be unordered set this._server = null @@ -95,6 +96,8 @@ class Connection extends events.EventEmitter { this.writable = true if (this._queued) this._unqueue() + binding.turbo_net_tcp_no_delay(this._handle, this.noDelay ? 1 : 0); + if (this._server) this._server.emit('connection', this) else this.emit('connect') } @@ -164,6 +167,11 @@ class Connection extends events.EventEmitter { else this._write(data, len, cb || noop) } + setNoDelay(value) { + this.noDelay = !!value; + binding.turbo_net_tcp_no_delay(this._handle, this.noDelay ? 1 : 0); + } + writev (datas, lens, cb) { if (typeof lens === 'function') this._writev(datas, getLengths(datas), lens) else if (!lens) this._writev(datas, getLengths(datas), cb || noop) diff --git a/src/turbo_net.c b/src/turbo_net.c index 2d38326..d5fa668 100644 --- a/src/turbo_net.c +++ b/src/turbo_net.c @@ -338,6 +338,21 @@ NAPI_METHOD(turbo_net_tcp_connect) { return NULL; } +NAPI_METHOD(turbo_net_tcp_no_delay) { + NAPI_ARGV(2) + NAPI_ARGV_BUFFER_CAST(turbo_net_tcp_t *, self, 0) + NAPI_ARGV_UINT32(nodelay, 1) + + int err; + NAPI_UV_THROWS(err, uv_tcp_nodelay( + &(self->handle), + nodelay + ) + ) + + return NULL; +} + NAPI_METHOD(turbo_net_on_fatal_exception) { NAPI_ARGV(1) @@ -351,6 +366,7 @@ NAPI_INIT() { NAPI_EXPORT_FUNCTION(turbo_net_tcp_destroy) NAPI_EXPORT_FUNCTION(turbo_net_tcp_listen) NAPI_EXPORT_FUNCTION(turbo_net_tcp_connect) + NAPI_EXPORT_FUNCTION(turbo_net_tcp_no_delay) NAPI_EXPORT_FUNCTION(turbo_net_tcp_port) NAPI_EXPORT_FUNCTION(turbo_net_tcp_write) NAPI_EXPORT_FUNCTION(turbo_net_tcp_write_two)