diff --git a/core/httpd.js b/core/httpd.js index 04847cb8..ff1bedbf 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -403,6 +403,8 @@ function handleConnection(client) { } } + client.noDelay = true; + client.onError(function(error) { logError(client.peerName + " - - [" + new Date() + "] " + error); }); diff --git a/core/network.js b/core/network.js index f9089e53..6f6b1fe3 100644 --- a/core/network.js +++ b/core/network.js @@ -14,6 +14,7 @@ Connection.prototype.connect = function(host, port) { let connection = this; connection.close(); connection.socket = new Socket(); + connection.socket.noDelay = true; return connection.socket.connect(host, port).then(function() { connection.buffer = ""; return Promise.all([ diff --git a/src/Socket.cpp b/src/Socket.cpp index a5891ebc..1b54ba3c 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -41,6 +41,7 @@ Socket::Socket(Task* task) { socketTemplate->SetAccessor(v8::String::NewFromUtf8(task->getIsolate(), "peerName"), getPeerName, 0, data); socketTemplate->SetAccessor(v8::String::NewFromUtf8(task->getIsolate(), "peerCertificate"), getPeerCertificate, 0, data); socketTemplate->SetAccessor(v8::String::NewFromUtf8(task->getIsolate(), "isConnected"), isConnected, 0, data); + socketTemplate->SetAccessor(v8::String::NewFromUtf8(task->getIsolate(), "noDelay"), getNoDelay, setNoDelay, data); v8::Local socketObject = socketTemplate->NewInstance(); socketObject->SetInternalField(0, v8::External::New(task->getIsolate(), this)); @@ -645,6 +646,20 @@ void Socket::isConnected(v8::Local property, const v8::PropertyCallb } } +void Socket::getNoDelay(v8::Local property, const v8::PropertyCallbackInfo& info) { + if (Socket* socket = Socket::get(info.Data())) { + info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), socket->_noDelay)); + } +} + +void Socket::setNoDelay(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { + v8::Maybe boolValue = value->BooleanValue(info.GetIsolate()->GetCurrentContext()); + if (Socket* socket = Socket::get(info.Data())) { + socket->_noDelay = boolValue.IsJust() && boolValue.FromJust(); + uv_tcp_nodelay(&socket->_socket, socket->_noDelay ? 1 : 0); + } +} + void Socket::create(const v8::FunctionCallbackInfo& args) { v8::HandleScope handleScope(args.GetIsolate()); if (Socket* socket = new Socket(Task::get(args.GetIsolate()))) { diff --git a/src/Socket.h b/src/Socket.h index fdb627bc..035e79ed 100644 --- a/src/Socket.h +++ b/src/Socket.h @@ -31,6 +31,7 @@ private: promiseid_t _closePromise = -1; int _refCount = 1; bool _connected = false; + bool _noDelay = false; std::string _peerName; enum Direction { kUndetermined, kAccept, kConnect }; @@ -61,6 +62,8 @@ private: static void getPeerName(v8::Local property, const v8::PropertyCallbackInfo& info); static void getPeerCertificate(v8::Local property, const v8::PropertyCallbackInfo& info); static void isConnected(v8::Local property, const v8::PropertyCallbackInfo& info); + static void getNoDelay(v8::Local property, const v8::PropertyCallbackInfo& info); + static void setNoDelay(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); static Socket* get(v8::Handle socketObject); static void onClose(uv_handle_t* handle);