From 10ff559ec39ccb27d9f12b41960207fe493a27e7 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 12 Nov 2010 11:31:39 -0800 Subject: [PATCH] Add IOWatcher.flush() To be called if sockets get too much data. This is to force a flush before the tick ends. --- lib/net.js | 4 ++++ src/node_io_watcher.cc | 15 +++++++++++++++ src/node_io_watcher.h | 2 ++ 3 files changed, 21 insertions(+) diff --git a/lib/net.js b/lib/net.js index 230d8e3a58..12db1f45e5 100644 --- a/lib/net.js +++ b/lib/net.js @@ -290,6 +290,10 @@ Stream.prototype.write = function (data, encoding, fd) { this._onWritable(); // Insert writeWatcher into the dumpQueue require('timers').active(this); + if (queueSize > (64*1024)) { + IOWatcher.flush(); + } + return queueSize < (64*1024); }; diff --git a/src/node_io_watcher.cc b/src/node_io_watcher.cc index 38f44cc46f..943deb7056 100644 --- a/src/node_io_watcher.cc +++ b/src/node_io_watcher.cc @@ -55,6 +55,10 @@ void IOWatcher::Initialize(Handle target) { Local io_watcher = constructor_template->GetFunction(); target->Set(String::NewSymbol("IOWatcher"), io_watcher); + NODE_SET_METHOD(constructor_template->GetFunction(), + "flush", + IOWatcher::Flush); + callback_symbol = NODE_PSYMBOL("callback"); next_sym = NODE_PSYMBOL("next"); @@ -194,6 +198,13 @@ Handle IOWatcher::Set(const Arguments& args) { return Undefined(); } + +Handle IOWatcher::Flush(const Arguments& args) { + HandleScope scope; // unneccessary? + IOWatcher::Dump(); + return Undefined(); +} + #define KB 1024 /* @@ -233,7 +244,11 @@ Handle IOWatcher::Set(const Arguments& args) { void IOWatcher::Dump(EV_P_ ev_prepare *w, int revents) { assert(revents == EV_PREPARE); assert(w == &dumper); + Dump(); +} + +void IOWatcher::Dump() { HandleScope scope; static struct iovec iov[IOV_MAX]; diff --git a/src/node_io_watcher.h b/src/node_io_watcher.h index 2c2de7809f..f1ae3babf1 100644 --- a/src/node_io_watcher.h +++ b/src/node_io_watcher.h @@ -26,6 +26,7 @@ class IOWatcher : ObjectWrap { } static v8::Handle New(const v8::Arguments& args); + static v8::Handle Flush(const v8::Arguments& args); static v8::Handle Start(const v8::Arguments& args); static v8::Handle Stop(const v8::Arguments& args); static v8::Handle Set(const v8::Arguments& args); @@ -34,6 +35,7 @@ class IOWatcher : ObjectWrap { static void Callback(EV_P_ ev_io *watcher, int revents); static void Dump(EV_P_ ev_prepare *watcher, int revents); + static void Dump(); void Start(); void Stop();