|
|
@ -1,3 +1,4 @@ |
|
|
|
var sys = require("./sys"); |
|
|
|
var debugLevel = 0; |
|
|
|
if ('NODE_DEBUG' in process.ENV) debugLevel = 1; |
|
|
|
function debug (x) { |
|
|
@ -118,19 +119,23 @@ function Socket (peerInfo) { |
|
|
|
if (!recvMsg.fd && bytesRead == 0) { |
|
|
|
self.readable = false; |
|
|
|
self._readWatcher.stop(); |
|
|
|
self.emit('end'); |
|
|
|
|
|
|
|
if (self._events && self._events['end']) self.emit('end'); |
|
|
|
if (self.onend) self.onend(); |
|
|
|
|
|
|
|
if (!self.writable) self.forceClose(); |
|
|
|
} else if (bytesRead > 0) { |
|
|
|
var start = recvBuffer.used; |
|
|
|
var end = recvBuffer.used + bytesRead; |
|
|
|
if (self.listeners('data').length) { |
|
|
|
|
|
|
|
if (self._events && self._events['data']) { |
|
|
|
// emit a slice
|
|
|
|
self.emit('data', recvBuffer.slice(start, end)); |
|
|
|
} |
|
|
|
if (self.listeners('dataLite').length) { |
|
|
|
// emit the original buffer with end points.
|
|
|
|
self.emit('dataLite', recvBuffer, start, end); |
|
|
|
} |
|
|
|
|
|
|
|
// Optimization: emit the original buffer with end points
|
|
|
|
if (self.ondata) self.ondata(recvBuffer, start, end); |
|
|
|
|
|
|
|
recvBuffer.used += bytesRead; |
|
|
|
} |
|
|
|
}; |
|
|
@ -141,15 +146,17 @@ function Socket (peerInfo) { |
|
|
|
self.sendQueueSize = 0; // in bytes, not to be confused with sendQueue.length!
|
|
|
|
self.sendMessageQueueSize = 0; // number of messages remaining to be sent
|
|
|
|
self._doFlush = function () { |
|
|
|
/* Socket becomes writeable on connect() but don't flush if there's |
|
|
|
* nothing actually to write */ |
|
|
|
// Socket becomes writeable on connect() but don't flush if there's
|
|
|
|
// nothing actually to write
|
|
|
|
if ((self.sendQueueSize == 0) && (self.sendMessageQueueSize == 0)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (self.flush()) { |
|
|
|
assert(self.sendQueueSize == 0); |
|
|
|
assert(self.sendMessageQueueSize == 0); |
|
|
|
self.emit("drain"); |
|
|
|
|
|
|
|
if (self._events && self._events['drain']) self.emit("drain"); |
|
|
|
if (self.ondrain) self.ondrain(); // Optimization
|
|
|
|
} |
|
|
|
}; |
|
|
|
self._writeWatcher = ioWatchers.alloc(); |
|
|
@ -302,7 +309,8 @@ Socket.prototype.sendFD = function(socketToPass) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Flushes the write buffer out. Emits "drain" if the buffer is empty.
|
|
|
|
// Flushes the write buffer out.
|
|
|
|
// Returns true if the entire buffer was flushed.
|
|
|
|
Socket.prototype.flush = function () { |
|
|
|
var self = this; |
|
|
|
|
|
|
@ -314,7 +322,7 @@ Socket.prototype.flush = function () { |
|
|
|
|
|
|
|
if (b == END_OF_FILE) { |
|
|
|
self._shutdown(); |
|
|
|
break; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (b.sent == b.used) { |
|
|
@ -338,7 +346,7 @@ Socket.prototype.flush = function () { |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
self.forceClose(e); |
|
|
|
return; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (bytesWritten === null) { |
|
|
|