Permalink
Browse files

be a bit more defensive about resume()

  • Loading branch information...
1 parent 57ab68c commit 5a694a3e7b7e5e86b9b3194be4269053e888d3a6 @alanszlosek committed Dec 21, 2011
Showing with 7 additions and 7 deletions.
  1. +7 −7 ftpd.js
View
14 ftpd.js
@@ -280,7 +280,7 @@ function createServer(host, sandbox) {
socket.write("226 Transfer OK\r\n");
pasvconn.end();
};
- pasvconn.resume();
+ if (pasvconn.readable) pasvconn.resume();
logIf(3, "Sending file list", socket);
fs.readdir(socket.sandbox + socket.fs.cwd(), function(err, files) {
var path = socket.sandbox + socket.fs.cwd();
@@ -414,26 +414,26 @@ function createServer(host, sandbox) {
socket.dataSocket = psocket;
// 150 should be sent before we send data on the data connection
//socket.write("150 Connection Accepted\r\n");
- socket.resume();
+ if (socket.readable) socket.resume();
});
psocket.on("end", function () {
logIf(3, "Passive data event: end", socket);
// remove pointer
socket.dataSocket = null;
- socket.resume(); // just in case
+ if (socket.readable) socket.resume(); // just in case
});
psocket.addListener("error", function(err) {
logIf(0, "Passive data event: error: " + err, socket);
socket.dataSocket = null;
- socket.resume();
+ if (socket.readable) socket.resume();
});
psocket.addListener("close", function(had_error) {
logIf(
(had_error ? 0 : 3),
"Passive data event: close " + (had_error ? " due to error" : ""),
socket
);
- socket.resume();
+ if (socket.readable) socket.resume();
});
});
// Once we're successfully listening, tell the client
@@ -449,7 +449,7 @@ function createServer(host, sandbox) {
});
pasv.on("close", function() {
logIf(3, "Passive data listener closed", socket);
- socket.resume(); // just in case
+ if (socket.readable) socket.resume(); // just in case
});
pasv.listen(0);
socket.dataListener = pasv;
@@ -654,7 +654,7 @@ function createServer(host, sandbox) {
});
logIf(3, "Told client ok to send file data", socket);
socket.write("150 Ok to send data\r\n"); // don't think resume() needs to wait for this to succeed
- dataSocket.resume();
+ if (dataSocket.readable) dataSocket.resume();
});
});
break;

0 comments on commit 5a694a3

Please sign in to comment.