|
|
@ -92,20 +92,25 @@ function Socket (peerInfo) { |
|
|
|
debug('recvBuffer.used ' + recvBuffer.used); |
|
|
|
var bytesRead; |
|
|
|
|
|
|
|
if (self.type == "unix") { |
|
|
|
bytesRead = recvMsg(self.fd, |
|
|
|
recvBuffer, |
|
|
|
recvBuffer.used, |
|
|
|
recvBuffer.length - recvBuffer.used); |
|
|
|
debug('recvMsg.fd ' + recvMsg.fd); |
|
|
|
if (recvMsg.fd) { |
|
|
|
self.emit('fd', recvMsg.fd); |
|
|
|
try { |
|
|
|
if (self.type == "unix") { |
|
|
|
bytesRead = recvMsg(self.fd, |
|
|
|
recvBuffer, |
|
|
|
recvBuffer.used, |
|
|
|
recvBuffer.length - recvBuffer.used); |
|
|
|
debug('recvMsg.fd ' + recvMsg.fd); |
|
|
|
if (recvMsg.fd) { |
|
|
|
self.emit('fd', recvMsg.fd); |
|
|
|
} |
|
|
|
} else { |
|
|
|
bytesRead = read(self.fd, |
|
|
|
recvBuffer, |
|
|
|
recvBuffer.used, |
|
|
|
recvBuffer.length - recvBuffer.used); |
|
|
|
} |
|
|
|
} else { |
|
|
|
bytesRead = read(self.fd, |
|
|
|
recvBuffer, |
|
|
|
recvBuffer.used, |
|
|
|
recvBuffer.length - recvBuffer.used); |
|
|
|
} catch (e) { |
|
|
|
self.forceClose(e); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
debug('bytesRead ' + bytesRead + '\n'); |
|
|
@ -320,15 +325,22 @@ Socket.prototype.flush = function () { |
|
|
|
} |
|
|
|
|
|
|
|
var fdToSend = null; |
|
|
|
if (b.isFd) { |
|
|
|
fdToSend = parseInt(b.asciiSlice(b.sent, b.used - b.sent)); |
|
|
|
bytesWritten = sendFD(self.fd, fdToSend); |
|
|
|
} else { |
|
|
|
bytesWritten = write(self.fd, |
|
|
|
b, |
|
|
|
b.sent, |
|
|
|
b.used - b.sent); |
|
|
|
|
|
|
|
try { |
|
|
|
if (b.isFd) { |
|
|
|
fdToSend = parseInt(b.asciiSlice(b.sent, b.used - b.sent)); |
|
|
|
bytesWritten = sendFD(self.fd, fdToSend); |
|
|
|
} else { |
|
|
|
bytesWritten = write(self.fd, |
|
|
|
b, |
|
|
|
b.sent, |
|
|
|
b.used - b.sent); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
self.forceClose(e); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (bytesWritten === null) { |
|
|
|
// could not flush everything
|
|
|
|
self._writeWatcher.start(); |
|
|
@ -451,7 +463,14 @@ Socket.prototype.forceClose = function (exception) { |
|
|
|
Socket.prototype._shutdown = function () { |
|
|
|
if (this.writable) { |
|
|
|
this.writable = false; |
|
|
|
shutdown(this.fd, 'write'); |
|
|
|
|
|
|
|
try { |
|
|
|
shutdown(this.fd, 'write') |
|
|
|
} catch (e) { |
|
|
|
this.forceClose(e); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (!this.readable) this.forceClose(); |
|
|
|
} |
|
|
|
}; |
|
|
|