Browse Source

Wrap syscalls with try-catch

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
d979a7993e
  1. 21
      lib/net.js

21
lib/net.js

@ -92,6 +92,7 @@ function Socket (peerInfo) {
debug('recvBuffer.used ' + recvBuffer.used); debug('recvBuffer.used ' + recvBuffer.used);
var bytesRead; var bytesRead;
try {
if (self.type == "unix") { if (self.type == "unix") {
bytesRead = recvMsg(self.fd, bytesRead = recvMsg(self.fd,
recvBuffer, recvBuffer,
@ -107,6 +108,10 @@ function Socket (peerInfo) {
recvBuffer.used, recvBuffer.used,
recvBuffer.length - recvBuffer.used); recvBuffer.length - recvBuffer.used);
} }
} catch (e) {
self.forceClose(e);
return;
}
debug('bytesRead ' + bytesRead + '\n'); debug('bytesRead ' + bytesRead + '\n');
@ -320,6 +325,8 @@ Socket.prototype.flush = function () {
} }
var fdToSend = null; var fdToSend = null;
try {
if (b.isFd) { if (b.isFd) {
fdToSend = parseInt(b.asciiSlice(b.sent, b.used - b.sent)); fdToSend = parseInt(b.asciiSlice(b.sent, b.used - b.sent));
bytesWritten = sendFD(self.fd, fdToSend); bytesWritten = sendFD(self.fd, fdToSend);
@ -329,6 +336,11 @@ Socket.prototype.flush = function () {
b.sent, b.sent,
b.used - 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…
Cancel
Save