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