diff --git a/lib/net.js b/lib/net.js index 230d8e3a58d..12db1f45e58 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 38f44cc46fa..943deb7056b 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 2c2de7809f9..f1ae3babf15 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();