forked from cory/tildefriends
Disable Nagle's algorithm to try to make things more uniformly responsive.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3368 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
86ee9b1829
commit
4cdbdaf3d1
@ -403,6 +403,8 @@ function handleConnection(client) {
|
||||
}
|
||||
}
|
||||
|
||||
client.noDelay = true;
|
||||
|
||||
client.onError(function(error) {
|
||||
logError(client.peerName + " - - [" + new Date() + "] " + error);
|
||||
});
|
||||
|
@ -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([
|
||||
|
@ -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<v8::Object> socketObject = socketTemplate->NewInstance();
|
||||
socketObject->SetInternalField(0, v8::External::New(task->getIsolate(), this));
|
||||
@ -645,6 +646,20 @@ void Socket::isConnected(v8::Local<v8::String> property, const v8::PropertyCallb
|
||||
}
|
||||
}
|
||||
|
||||
void Socket::getNoDelay(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
if (Socket* socket = Socket::get(info.Data())) {
|
||||
info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), socket->_noDelay));
|
||||
}
|
||||
}
|
||||
|
||||
void Socket::setNoDelay(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) {
|
||||
v8::Maybe<bool> 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<v8::Value>& args) {
|
||||
v8::HandleScope handleScope(args.GetIsolate());
|
||||
if (Socket* socket = new Socket(Task::get(args.GetIsolate()))) {
|
||||
|
@ -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<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info);
|
||||
static void getPeerCertificate(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info);
|
||||
static void isConnected(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info);
|
||||
static void getNoDelay(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info);
|
||||
static void setNoDelay(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info);
|
||||
|
||||
static Socket* get(v8::Handle<v8::Value> socketObject);
|
||||
static void onClose(uv_handle_t* handle);
|
||||
|
Loading…
Reference in New Issue
Block a user