Browse Source

tcp_wrap: add writeQueueSize

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
97296e405c
  1. 13
      src/tcp_wrap.cc
  2. 9
      test/simple/test-tcp-wrap-listen.js

13
src/tcp_wrap.cc

@ -59,6 +59,7 @@ static uv_tcp_t* handle_that_last_alloced;
static Persistent<String> slab_sym;
static Persistent<String> buffer_sym;
static Persistent<String> write_queue_size_sym;
class TCPWrap;
@ -104,6 +105,8 @@ class TCPWrap {
slab_sym = Persistent<String>::New(String::NewSymbol("slab"));
buffer_sym = Persistent<String>::New(String::NewSymbol("buffer"));
write_queue_size_sym =
Persistent<String>::New(String::NewSymbol("writeQueueSize"));
target->Set(String::NewSymbol("TCP"), constructor);
}
@ -131,6 +134,8 @@ class TCPWrap {
assert(object->InternalFieldCount() > 0);
object_ = v8::Persistent<v8::Object>::New(object);
object_->SetPointerInInternalField(0, this);
UpdateWriteQueueSize();
}
~TCPWrap() {
@ -143,6 +148,10 @@ class TCPWrap {
delete wrap;
}
inline void UpdateWriteQueueSize() {
object_->Set(write_queue_size_sym, Integer::New(handle_.write_queue_size));
}
static Handle<Value> Bind(const Arguments& args) {
HandleScope scope;
@ -347,6 +356,8 @@ class TCPWrap {
SetErrno(uv_last_error().code);
}
wrap->UpdateWriteQueueSize();
Local<Value> argv[4] = {
Integer::New(status),
Local<Value>::New(wrap->object_),
@ -396,6 +407,8 @@ class TCPWrap {
// Error starting the TCP.
if (r) SetErrno(uv_last_error().code);
wrap->UpdateWriteQueueSize();
return scope.Close(req_wrap->object_);
}

9
test/simple/test-tcp-wrap-listen.js

@ -16,6 +16,7 @@ var writeCount = 0;
var recvCount = 0;
server.onconnection = function(client) {
assert.equal(0, client.writeQueueSize);
console.log("got connection");
function maybeCloseClient() {
@ -31,9 +32,14 @@ server.onconnection = function(client) {
if (buffer) {
assert.ok(length > 0);
assert.equal(0, client.writeQueueSize);
var req = client.write(buffer, offset, length);
client.pendingWrites.push(req);
console.log("client.writeQueueSize: " + client.writeQueueSize);
assert.equal(length, client.writeQueueSize);
req.oncomplete = function(status, client_, req_, buffer_) {
assert.equal(req, client.pendingWrites.shift());
@ -43,6 +49,9 @@ server.onconnection = function(client) {
assert.equal(req, req_);
assert.equal(buffer, buffer_);
console.log("client.writeQueueSize: " + client.writeQueueSize);
assert.equal(0, client.writeQueueSize);
writeCount++;
console.log("write " + writeCount);
maybeCloseClient();

Loading…
Cancel
Save