Wrap syscalls with try-catch
This commit is contained in:
parent
263813ae3e
commit
d979a7993e
63
lib/net.js
63
lib/net.js
@ -92,20 +92,25 @@ function Socket (peerInfo) {
|
|||||||
debug('recvBuffer.used ' + recvBuffer.used);
|
debug('recvBuffer.used ' + recvBuffer.used);
|
||||||
var bytesRead;
|
var bytesRead;
|
||||||
|
|
||||||
if (self.type == "unix") {
|
try {
|
||||||
bytesRead = recvMsg(self.fd,
|
if (self.type == "unix") {
|
||||||
recvBuffer,
|
bytesRead = recvMsg(self.fd,
|
||||||
recvBuffer.used,
|
recvBuffer,
|
||||||
recvBuffer.length - recvBuffer.used);
|
recvBuffer.used,
|
||||||
debug('recvMsg.fd ' + recvMsg.fd);
|
recvBuffer.length - recvBuffer.used);
|
||||||
if (recvMsg.fd) {
|
debug('recvMsg.fd ' + recvMsg.fd);
|
||||||
self.emit('fd', recvMsg.fd);
|
if (recvMsg.fd) {
|
||||||
|
self.emit('fd', recvMsg.fd);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bytesRead = read(self.fd,
|
||||||
|
recvBuffer,
|
||||||
|
recvBuffer.used,
|
||||||
|
recvBuffer.length - recvBuffer.used);
|
||||||
}
|
}
|
||||||
} else {
|
} catch (e) {
|
||||||
bytesRead = read(self.fd,
|
self.forceClose(e);
|
||||||
recvBuffer,
|
return;
|
||||||
recvBuffer.used,
|
|
||||||
recvBuffer.length - recvBuffer.used);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug('bytesRead ' + bytesRead + '\n');
|
debug('bytesRead ' + bytesRead + '\n');
|
||||||
@ -320,15 +325,22 @@ Socket.prototype.flush = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fdToSend = null;
|
var fdToSend = null;
|
||||||
if (b.isFd) {
|
|
||||||
fdToSend = parseInt(b.asciiSlice(b.sent, b.used - b.sent));
|
try {
|
||||||
bytesWritten = sendFD(self.fd, fdToSend);
|
if (b.isFd) {
|
||||||
} else {
|
fdToSend = parseInt(b.asciiSlice(b.sent, b.used - b.sent));
|
||||||
bytesWritten = write(self.fd,
|
bytesWritten = sendFD(self.fd, fdToSend);
|
||||||
b,
|
} else {
|
||||||
b.sent,
|
bytesWritten = write(self.fd,
|
||||||
b.used - b.sent);
|
b,
|
||||||
|
b.sent,
|
||||||
|
b.used - b.sent);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
self.forceClose(e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesWritten === null) {
|
if (bytesWritten === null) {
|
||||||
// could not flush everything
|
// could not flush everything
|
||||||
self._writeWatcher.start();
|
self._writeWatcher.start();
|
||||||
@ -451,7 +463,14 @@ Socket.prototype.forceClose = function (exception) {
|
|||||||
Socket.prototype._shutdown = function () {
|
Socket.prototype._shutdown = function () {
|
||||||
if (this.writable) {
|
if (this.writable) {
|
||||||
this.writable = false;
|
this.writable = false;
|
||||||
shutdown(this.fd, 'write');
|
|
||||||
|
try {
|
||||||
|
shutdown(this.fd, 'write')
|
||||||
|
} catch (e) {
|
||||||
|
this.forceClose(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.readable) this.forceClose();
|
if (!this.readable) this.forceClose();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user