From f120638b0515833f53ef1441de3271e492d7451c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 9 Nov 2010 12:30:29 -0800 Subject: [PATCH] working --- src/node_io_watcher.cc | 59 +++------------------------------ test/simple/test-dumper-unix.js | 39 ++++++++++++---------- test/simple/test-dumper.js | 31 +++++++++-------- 3 files changed, 43 insertions(+), 86 deletions(-) diff --git a/src/node_io_watcher.cc b/src/node_io_watcher.cc index ee6871b54c1..146c2bd70df 100644 --- a/src/node_io_watcher.cc +++ b/src/node_io_watcher.cc @@ -75,8 +75,6 @@ void IOWatcher::Initialize(Handle target) { dump_queue = Persistent::New(Object::New()); io_watcher->Set(String::NewSymbol("dumpQueue"), dump_queue); - dump_queue->Set(next_sym, dump_queue); - dump_queue->Set(prev_sym, dump_queue); } @@ -227,43 +225,6 @@ Handle IOWatcher::Set(const Arguments& args) { #endif -namespace linklist { - - inline void Remove(Handle b) { - Local b_next = b->Get(next_sym)->ToObject(); - Local b_prev = b->Get(prev_sym)->ToObject(); - - // b.next.prev = b.prev - b_next->Set(prev_sym, b_prev); - - // b.prev.next = b.next - b_prev->Set(next_sym, b_next); - } - - - inline void Append(Handle list, Handle b) { - // b.next = list - b->Set(next_sym, list); - - // b.prev = list.prev - b->Set(prev_sym, list); - - // list.prev.next = b - Local list_prev = list->Get(prev_sym)->ToObject(); - list_prev->Set(next_sym, b); - - // list.prev = b - list->Set(prev_sym, b); - } - - - inline bool Empty(Handle list) { - // list.next === list - return list->Get(next_sym)->StrictEquals(list); - } -} - - void IOWatcher::Dump(EV_P_ ev_prepare *w, int revents) { assert(revents == EV_PREPARE); assert(w == &dumper); @@ -329,20 +290,6 @@ void IOWatcher::Dump(EV_P_ ev_prepare *w, int revents) { } size_t first_offset = offset; - // Note that watcher.buckets points to a linked-list - // of buckets. - Local first_bucket_v = watcher->Get(first_bucket_sym); - if (!first_bucket_v->IsObject()) { - // It is possible that someone did - // - // socket.write("data"); socket.destroy(); - // - // In which case we'll have a watcher in the dump_queue which is - // no longer associated with a socket. In this case we just - // skip it. - assert(!watcher->Get(last_bucket_sym)->IsObject()); - continue; - } // Loop over all the buckets for this particular watcher/socket in order // to fill iov. @@ -350,12 +297,12 @@ void IOWatcher::Dump(EV_P_ ev_prepare *w, int revents) { Local bucket; unsigned int bucket_index = 0; - for (bucket_v = first_bucket_v; + for (bucket_v = watcher->Get(first_bucket_sym); // Break if we have an FD to send. // sendmsg can only handle one FD at a time. fd_to_send < 0 && // break if we've hit the end - !bucket_v->IsObject() && + bucket_v->IsObject() && // break if iov contains a lot of data to_write < max_to_write && // break if iov is running out of space @@ -403,6 +350,8 @@ void IOWatcher::Dump(EV_P_ ev_prepare *w, int revents) { } } + if (to_write == 0) continue; + ssize_t written; if (unix_socket) { diff --git a/test/simple/test-dumper-unix.js b/test/simple/test-dumper-unix.js index 278345155d0..04881a02461 100644 --- a/test/simple/test-dumper-unix.js +++ b/test/simple/test-dumper-unix.js @@ -18,8 +18,15 @@ function test (N, b, cb) { // Use writev/dumper to send data down the one of the sockets, fds[1]. // This requires a IOWatcher. var w = new IOWatcher(); + w.set(fds[1], false, true); w.isUnixSocket = true; - w.set(fds[1], false, false); + + w.callback = function (readable, writable) { + assert.ok(!readable && writable); // not really important. + // Insert watcher into dumpQueue + w.next = IOWatcher.dumpQueue.next; + IOWatcher.dumpQueue.next = w; + } var ndrain = 0; w.ondrain = function () { @@ -61,11 +68,9 @@ function test (N, b, cb) { stream.on('close', function () { assert.equal(fdsSent, fdsRecv); // check to make sure the watcher isn't in the dump queue. - var x = IOWatcher.dumpQueue; - do { + for (var x = IOWatcher.dumpQueue; x; x = x.next) { assert.ok(x !== w); - x = x.next; - } while (x !== IOWatcher.dumpQueue); + } ncomplete++; if (cb) cb(); @@ -76,19 +81,17 @@ function test (N, b, cb) { w.next = IOWatcher.dumpQueue.next; IOWatcher.dumpQueue.next = w; - if (N > 0) { - w.firstBucket = { data: b }; - w.lastBucket = w.firstBucket; - - for (var i = 0; i < N-1; i++) { - var bucket = { data: b }; - w.lastBucket.next = bucket; - w.lastBucket = bucket; - // Kind of randomly fill these buckets with fds. - if (fdsSent < 5 && i % 2 == 0) { - bucket.fd = 1; // send stdout - fdsSent++; - } + w.firstBucket = { data: b }; + w.lastBucket = w.firstBucket; + + for (var i = 0; i < N-1; i++) { + var bucket = { data: b }; + w.lastBucket.next = bucket; + w.lastBucket = bucket; + // Kind of randomly fill these buckets with fds. + if (fdsSent < 5 && i % 2 == 0) { + bucket.fd = 1; // send stdout + fdsSent++; } } } diff --git a/test/simple/test-dumper.js b/test/simple/test-dumper.js index edb40457813..4726bbb6af5 100644 --- a/test/simple/test-dumper.js +++ b/test/simple/test-dumper.js @@ -16,11 +16,19 @@ function test (N, b, cb) { // Create a pipe var fds = process.binding('net').pipe(); + console.log("fds == %j", fds); // Use writev/dumper to send data down the write end of the pipe, fds[1]. // This requires a IOWatcher. var w = new IOWatcher(); - w.set(fds[1], false, false); + w.set(fds[1], false, true); + + w.callback = function (readable, writable) { + assert.ok(!readable && writable); // not really important. + // Insert watcher into dumpQueue + w.next = IOWatcher.dumpQueue.next; + IOWatcher.dumpQueue.next = w; + } var ndrain = 0; w.ondrain = function () { @@ -57,11 +65,9 @@ function test (N, b, cb) { stream.on('close', function () { // check to make sure the watcher isn't in the dump queue. - var x = IOWatcher.dumpQueue; - do { + for (var x = IOWatcher.dumpQueue; x; x = x.next) { assert.ok(x !== w); - x = x.next; - } while (x !== IOWatcher.dumpQueue); + } ncomplete++; if (cb) cb(); @@ -72,15 +78,14 @@ function test (N, b, cb) { w.next = IOWatcher.dumpQueue.next; IOWatcher.dumpQueue.next = w; - if (N > 0) { - w.firstBucket = { data: b }; - w.lastBucket = w.firstBucket; + w.firstBucket = { data: b }; + w.lastBucket = w.firstBucket; - for (var i = 0; i < N-1; i++) { - var bucket = { data: b }; - w.lastBucket.next = bucket; - w.lastBucket = bucket; - } + for (var i = 0; i < N-1; i++) { + var bucket = { data: b }; + assert.ok(!w.lastBucket.next); + w.lastBucket.next = bucket; + w.lastBucket = bucket; } }