Browse Source

Add IOWatcher.flush()

To be called if sockets get too much data. This is to force a flush before
the tick ends.
v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
10ff559ec3
  1. 4
      lib/net.js
  2. 15
      src/node_io_watcher.cc
  3. 2
      src/node_io_watcher.h

4
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);
};

15
src/node_io_watcher.cc

@ -55,6 +55,10 @@ void IOWatcher::Initialize(Handle<Object> target) {
Local<Function> 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<Value> IOWatcher::Set(const Arguments& args) {
return Undefined();
}
Handle<Value> IOWatcher::Flush(const Arguments& args) {
HandleScope scope; // unneccessary?
IOWatcher::Dump();
return Undefined();
}
#define KB 1024
/*
@ -233,7 +244,11 @@ Handle<Value> 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];

2
src/node_io_watcher.h

@ -26,6 +26,7 @@ class IOWatcher : ObjectWrap {
}
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> Flush(const v8::Arguments& args);
static v8::Handle<v8::Value> Start(const v8::Arguments& args);
static v8::Handle<v8::Value> Stop(const v8::Arguments& args);
static v8::Handle<v8::Value> 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();

Loading…
Cancel
Save