Update stream API: forceClose() -> destroy(), close() -> end()
This commit is contained in:
parent
7faf7d5c8d
commit
50c70ac714
@ -1,7 +1,7 @@
|
|||||||
path = require("path");
|
path = require("path");
|
||||||
|
|
||||||
var puts = require("sys").puts;
|
var puts = require("sys").puts;
|
||||||
var old = true;
|
var old = false;
|
||||||
|
|
||||||
http = require(old ? "http_old" : 'http');
|
http = require(old ? "http_old" : 'http');
|
||||||
if (old) puts('old version');
|
if (old) puts('old version');
|
||||||
@ -56,6 +56,6 @@ http.createServer(function (req, res) {
|
|||||||
res.write(body, 'ascii');
|
res.write(body, 'ascii');
|
||||||
res.close();
|
res.close();
|
||||||
} else {
|
} else {
|
||||||
res.close(body, 'ascii');
|
res.end(body, 'ascii');
|
||||||
}
|
}
|
||||||
}).listen(8000);
|
}).listen(8000);
|
||||||
|
35
lib/fs.js
35
lib/fs.js
@ -526,7 +526,7 @@ FileReadStream.prototype._read = function () {
|
|||||||
|
|
||||||
if (bytesRead === 0) {
|
if (bytesRead === 0) {
|
||||||
self.emit('end');
|
self.emit('end');
|
||||||
self.forceClose();
|
self.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +547,18 @@ FileReadStream.prototype._read = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var readStreamForceCloseWarning;
|
||||||
|
|
||||||
FileReadStream.prototype.forceClose = function (cb) {
|
FileReadStream.prototype.forceClose = function (cb) {
|
||||||
|
if (!readStreamForceCloseWarning) {
|
||||||
|
readStreamForceCloseWarning = "FileReadStream.prototype.forceClose renamed to destroy()";
|
||||||
|
sys.error(readStreamForceCloseWarning);
|
||||||
|
}
|
||||||
|
return this.destroy(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FileReadStream.prototype.destroy = function (cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.readable = false;
|
this.readable = false;
|
||||||
|
|
||||||
@ -691,13 +702,35 @@ FileWriteStream.prototype.write = function(data, cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var writeStreamCloseWarning;
|
||||||
|
|
||||||
FileWriteStream.prototype.close = function (cb) {
|
FileWriteStream.prototype.close = function (cb) {
|
||||||
|
if (!writeStreamCloseWarning) {
|
||||||
|
writeStreamCloseWarning = "FileWriteStream.prototype.close renamed to end()";
|
||||||
|
sys.error(writeStreamCloseWarning);
|
||||||
|
}
|
||||||
|
return this.end(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FileWriteStream.prototype.end = function (cb) {
|
||||||
this.writeable = false;
|
this.writeable = false;
|
||||||
this._queue.push([fs.close, cb]);
|
this._queue.push([fs.close, cb]);
|
||||||
this.flush();
|
this.flush();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var writeStreamForceCloseWarning;
|
||||||
|
|
||||||
|
FileWriteStream.prototype.forceClose = function (cb) {
|
||||||
|
if (!writeStreamForceCloseWarning) {
|
||||||
|
writeStreamForceCloseWarning = "FileWriteStream.prototype.forceClose renamed to destroy()";
|
||||||
|
sys.error(writeStreamForceCloseWarning);
|
||||||
|
}
|
||||||
|
return this.destroy(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FileWriteStream.prototype.forceClose = function (cb) {
|
FileWriteStream.prototype.forceClose = function (cb) {
|
||||||
this.writeable = false;
|
this.writeable = false;
|
||||||
fs.close(self.fd, function(err) {
|
fs.close(self.fd, function(err) {
|
||||||
|
43
lib/http.js
43
lib/http.js
@ -372,7 +372,17 @@ OutgoingMessage.prototype.finish = function () {
|
|||||||
throw new Error("finish() has been renamed to close().");
|
throw new Error("finish() has been renamed to close().");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var closeWarning;
|
||||||
|
|
||||||
OutgoingMessage.prototype.close = function (data, encoding) {
|
OutgoingMessage.prototype.close = function (data, encoding) {
|
||||||
|
if (!closeWarning) {
|
||||||
|
closeWarning = "OutgoingMessage.prototype.close has been renamed to end()";
|
||||||
|
sys.error(closeWarning);
|
||||||
|
}
|
||||||
|
return this.end(data, encoding);
|
||||||
|
};
|
||||||
|
|
||||||
|
OutgoingMessage.prototype.end = function (data, encoding) {
|
||||||
if (data) this.write(data, encoding);
|
if (data) this.write(data, encoding);
|
||||||
if (this.chunkedEncoding) this._send("0\r\n\r\n"); // last chunk
|
if (this.chunkedEncoding) this._send("0\r\n\r\n"); // last chunk
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
@ -436,19 +446,34 @@ sys.inherits(ClientRequest, OutgoingMessage);
|
|||||||
exports.ClientRequest = ClientRequest;
|
exports.ClientRequest = ClientRequest;
|
||||||
|
|
||||||
ClientRequest.prototype.finish = function () {
|
ClientRequest.prototype.finish = function () {
|
||||||
throw new Error( "finish() has been renamed to close() and no longer takes "
|
throw new Error( "finish() has been renamed to end() and no longer takes "
|
||||||
+ "a response handler as an argument. Manually add a 'response' listener "
|
+ "a response handler as an argument. Manually add a 'response' listener "
|
||||||
+ "to the request object."
|
+ "to the request object."
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var clientRequestCloseWarning;
|
||||||
|
|
||||||
ClientRequest.prototype.close = function () {
|
ClientRequest.prototype.close = function () {
|
||||||
|
if (!clientRequestCloseWarning) {
|
||||||
|
clientRequestCloseWarning = "Warning: ClientRequest.prototype.close has been renamed to end()";
|
||||||
|
sys.error(clientRequestCloseWarning);
|
||||||
|
}
|
||||||
if (arguments.length > 0) {
|
if (arguments.length > 0) {
|
||||||
throw new Error( "ClientRequest.prototype.close does not take any arguments. "
|
throw new Error( "ClientRequest.prototype.end does not take any arguments. "
|
||||||
+ "Add a response listener manually to the request object."
|
+ "Add a response listener manually to the request object."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
OutgoingMessage.prototype.close.call(this);
|
return this.end();
|
||||||
|
};
|
||||||
|
|
||||||
|
ClientRequest.prototype.end = function () {
|
||||||
|
if (arguments.length > 0) {
|
||||||
|
throw new Error( "ClientRequest.prototype.end does not take any arguments. "
|
||||||
|
+ "Add a response listener manually to the request object."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
OutgoingMessage.prototype.end.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -509,7 +534,7 @@ function connectionListener (socket) {
|
|||||||
freeParser(parser);
|
freeParser(parser);
|
||||||
|
|
||||||
if (responses.length == 0) {
|
if (responses.length == 0) {
|
||||||
socket.close();
|
socket.end();
|
||||||
} else {
|
} else {
|
||||||
responses[responses.length-1].closeOnFinish = true;
|
responses[responses.length-1].closeOnFinish = true;
|
||||||
}
|
}
|
||||||
@ -525,7 +550,7 @@ function connectionListener (socket) {
|
|||||||
res.shouldKeepAlive = shouldKeepAlive;
|
res.shouldKeepAlive = shouldKeepAlive;
|
||||||
res.addListener('flush', function () {
|
res.addListener('flush', function () {
|
||||||
if (flushMessageQueue(socket, responses)) {
|
if (flushMessageQueue(socket, responses)) {
|
||||||
socket.close();
|
socket.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
responses.push(res);
|
responses.push(res);
|
||||||
@ -582,7 +607,7 @@ function Client ( ) {
|
|||||||
parser.finish();
|
parser.finish();
|
||||||
|
|
||||||
debug("self got end closing. readyState = " + self.readyState);
|
debug("self got end closing. readyState = " + self.readyState);
|
||||||
self.close();
|
self.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addListener("close", function (e) {
|
self.addListener("close", function (e) {
|
||||||
@ -604,7 +629,7 @@ function Client ( ) {
|
|||||||
|
|
||||||
res.addListener('end', function ( ) {
|
res.addListener('end', function ( ) {
|
||||||
debug("request complete disconnecting. readyState = " + self.readyState);
|
debug("request complete disconnecting. readyState = " + self.readyState);
|
||||||
self.close();
|
self.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
currentRequest.emit("response", res);
|
currentRequest.emit("response", res);
|
||||||
@ -697,7 +722,7 @@ exports.cat = function (url, encoding_, headers_) {
|
|||||||
req.addListener('response', function (res) {
|
req.addListener('response', function (res) {
|
||||||
if (res.statusCode < 200 || res.statusCode >= 300) {
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
||||||
if (callback) callback(res.statusCode);
|
if (callback) callback(res.statusCode);
|
||||||
client.close();
|
client.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.setBodyEncoding(encoding);
|
res.setBodyEncoding(encoding);
|
||||||
@ -711,5 +736,5 @@ exports.cat = function (url, encoding_, headers_) {
|
|||||||
if (callback) callback(err);
|
if (callback) callback(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
req.close();
|
req.end();
|
||||||
};
|
};
|
||||||
|
40
lib/net.js
40
lib/net.js
@ -136,7 +136,7 @@ var timeout = new (function () {
|
|||||||
remove(first);
|
remove(first);
|
||||||
assert(first != peek(list));
|
assert(first != peek(list));
|
||||||
first.emit('timeout');
|
first.emit('timeout');
|
||||||
first.forceClose(new Error('idle timeout'));
|
first.destroy(new Error('idle timeout'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug(msecs + ' list empty');
|
debug(msecs + ' list empty');
|
||||||
@ -277,7 +277,7 @@ function initStream (self) {
|
|||||||
pool.used,
|
pool.used,
|
||||||
pool.length - pool.used);
|
pool.length - pool.used);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
self.forceClose(e);
|
self.destroy(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ function initStream (self) {
|
|||||||
if (self._events && self._events['end']) self.emit('end');
|
if (self._events && self._events['end']) self.emit('end');
|
||||||
if (self.onend) self.onend();
|
if (self.onend) self.onend();
|
||||||
|
|
||||||
if (!self.writable) self.forceClose();
|
if (!self.writable) self.destroy();
|
||||||
} else if (bytesRead > 0) {
|
} else if (bytesRead > 0) {
|
||||||
|
|
||||||
timeout.active(self);
|
timeout.active(self);
|
||||||
@ -485,7 +485,7 @@ Stream.prototype._writeOut = function (data, encoding) {
|
|||||||
try {
|
try {
|
||||||
bytesWritten = write(this.fd, buffer, off, len);
|
bytesWritten = write(this.fd, buffer, off, len);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.forceClose(e);
|
this.destroy(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +563,7 @@ function doConnect (socket, port, host) {
|
|||||||
try {
|
try {
|
||||||
connect(socket.fd, port, host);
|
connect(socket.fd, port, host);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
socket.forceClose(e);
|
socket.destroy(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,7 +589,7 @@ function doConnect (socket, port, host) {
|
|||||||
socket._writeWatcher.callback = _doFlush;
|
socket._writeWatcher.callback = _doFlush;
|
||||||
socket.emit('connect');
|
socket.emit('connect');
|
||||||
} else if (errno != EINPROGRESS) {
|
} else if (errno != EINPROGRESS) {
|
||||||
socket.forceClose(errnoException(errno, 'connect'));
|
socket.destroy(errnoException(errno, 'connect'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -660,7 +660,18 @@ Stream.prototype.resume = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Stream.prototype.forceClose = function (exception) {
|
var forceCloseWarning;
|
||||||
|
|
||||||
|
Stream.prototype.forceClose = function (e) {
|
||||||
|
if (!forceCloseWarning) {
|
||||||
|
forceCloseWarning = "forceClose() has been renamed to destroy()";
|
||||||
|
sys.error(forceCloseWarning);
|
||||||
|
}
|
||||||
|
return this.destroy(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Stream.prototype.destroy = function (exception) {
|
||||||
// pool is shared between sockets, so don't need to free it here.
|
// pool is shared between sockets, so don't need to free it here.
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@ -701,18 +712,27 @@ Stream.prototype._shutdown = function () {
|
|||||||
try {
|
try {
|
||||||
shutdown(this.fd, 'write')
|
shutdown(this.fd, 'write')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.forceClose(e);
|
this.destroy(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.readable) this.forceClose();
|
if (!this.readable) this.destroy();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var closeDepricationWarning;
|
||||||
|
|
||||||
Stream.prototype.close = function (data, encoding) {
|
Stream.prototype.close = function (data, encoding) {
|
||||||
if (data) this.write(data, encoding);
|
if (!closeDepricationWarning) {
|
||||||
|
closeDepricationWarning = "Notification: Stream.prototype.close has been renamed to end()";
|
||||||
|
sys.error(closeDepricationWarning);
|
||||||
|
}
|
||||||
|
return this.end(data, encoding);
|
||||||
|
};
|
||||||
|
|
||||||
|
Stream.prototype.end = function (data, encoding) {
|
||||||
if (this.writable) {
|
if (this.writable) {
|
||||||
|
if (data) this.write(data, encoding);
|
||||||
if (this._writeQueueLast() != END_OF_FILE) {
|
if (this._writeQueueLast() != END_OF_FILE) {
|
||||||
this._writeQueue.push(END_OF_FILE);
|
this._writeQueue.push(END_OF_FILE);
|
||||||
this.flush();
|
this.flush();
|
||||||
|
@ -8,7 +8,7 @@ var errorCount = 0;
|
|||||||
var eofCount = 0;
|
var eofCount = 0;
|
||||||
|
|
||||||
var server = tcp.createServer(function(socket) {
|
var server = tcp.createServer(function(socket) {
|
||||||
socket.close();
|
socket.end();
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ var request = client.request("GET", "/", {"host": "localhost"});
|
|||||||
request.addListener('response', function(response) {
|
request.addListener('response', function(response) {
|
||||||
sys.puts("STATUS: " + response.statusCode);
|
sys.puts("STATUS: " + response.statusCode);
|
||||||
});
|
});
|
||||||
request.close();
|
request.end();
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
server.close();
|
server.close();
|
||||||
|
@ -10,7 +10,7 @@ server = http.createServer(function (req, res) {
|
|||||||
"Content-Type": "text/plain",
|
"Content-Type": "text/plain",
|
||||||
});
|
});
|
||||||
res.write(body);
|
res.write(body);
|
||||||
res.close();
|
res.end();
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ var server = net.createServer(function (c) {
|
|||||||
total_connections++;
|
total_connections++;
|
||||||
print("#");
|
print("#");
|
||||||
c.write(body);
|
c.write(body);
|
||||||
c.close();
|
c.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
@ -41,7 +41,7 @@ function runClient (callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.addListener("end", function () {
|
client.addListener("end", function () {
|
||||||
client.close();
|
client.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.addListener("error", function (e) {
|
client.addListener("error", function (e) {
|
||||||
|
@ -5,7 +5,7 @@ N = 200;
|
|||||||
server = net.createServer(function (connection) {
|
server = net.createServer(function (connection) {
|
||||||
function write (j) {
|
function write (j) {
|
||||||
if (j >= N) {
|
if (j >= N) {
|
||||||
connection.close();
|
connection.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@ -58,7 +58,7 @@ setTimeout(function () {
|
|||||||
|
|
||||||
client.addListener("end", function () {
|
client.addListener("end", function () {
|
||||||
server.close();
|
server.close();
|
||||||
client.close();
|
client.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
|
@ -8,7 +8,7 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
var N = 100;
|
var N = 100;
|
||||||
var DELAY = 1;
|
var DELAY = 1;
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var client_closed = false;
|
var client_ended = false;
|
||||||
|
|
||||||
var server = net.createServer(function (socket) {
|
var server = net.createServer(function (socket) {
|
||||||
socket.setEncoding("utf8");
|
socket.setEncoding("utf8");
|
||||||
@ -32,11 +32,11 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
socket.addListener("end", function () {
|
socket.addListener("end", function () {
|
||||||
puts("server-side socket EOF");
|
puts("server-side socket EOF");
|
||||||
assert.equal("writeOnly", socket.readyState);
|
assert.equal("writeOnly", socket.readyState);
|
||||||
socket.close();
|
socket.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("close", function (had_error) {
|
socket.addListener("close", function (had_error) {
|
||||||
puts("server-side socket close");
|
puts("server-side socket.end");
|
||||||
assert.equal(false, had_error);
|
assert.equal(false, had_error);
|
||||||
assert.equal("closed", socket.readyState);
|
assert.equal("closed", socket.readyState);
|
||||||
socket.server.close();
|
socket.server.close();
|
||||||
@ -64,8 +64,8 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
client.write("PING");
|
client.write("PING");
|
||||||
} else {
|
} else {
|
||||||
puts("closing client");
|
puts("closing client");
|
||||||
client.close();
|
client.end();
|
||||||
client_closed = true;
|
client_ended = true;
|
||||||
}
|
}
|
||||||
}, DELAY);
|
}, DELAY);
|
||||||
});
|
});
|
||||||
@ -76,9 +76,9 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.addListener("close", function () {
|
client.addListener("close", function () {
|
||||||
puts("client close");
|
puts("client.end");
|
||||||
assert.equal(N+1, count);
|
assert.equal(N+1, count);
|
||||||
assert.equal(true, client_closed);
|
assert.ok(client_ended);
|
||||||
if (on_complete) on_complete();
|
if (on_complete) on_complete();
|
||||||
tests_run += 1;
|
tests_run += 1;
|
||||||
});
|
});
|
||||||
|
@ -33,7 +33,7 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
|
|
||||||
socket.addListener("end", function () {
|
socket.addListener("end", function () {
|
||||||
assert.equal("writeOnly", socket.readyState);
|
assert.equal("writeOnly", socket.readyState);
|
||||||
socket.close();
|
socket.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("close", function (had_error) {
|
socket.addListener("close", function (had_error) {
|
||||||
@ -71,7 +71,7 @@ function pingPongTest (port, host, on_complete) {
|
|||||||
} else {
|
} else {
|
||||||
sent_final_ping = true;
|
sent_final_ping = true;
|
||||||
client.write("PING");
|
client.write("PING");
|
||||||
client.close();
|
client.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ puts("start server on port " + PORT);
|
|||||||
server = net.createServer(function (connection) {
|
server = net.createServer(function (connection) {
|
||||||
connection.addListener("connect", function () {
|
connection.addListener("connect", function () {
|
||||||
assert.equal(false, connection.write(body));
|
assert.equal(false, connection.write(body));
|
||||||
connection.close();
|
connection.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
@ -46,7 +46,7 @@ client.addListener("data", function (d) {
|
|||||||
|
|
||||||
client.addListener("end", function () {
|
client.addListener("end", function () {
|
||||||
server.close();
|
server.close();
|
||||||
client.close();
|
client.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
|
@ -20,7 +20,7 @@ var echo_server = net.createServer(function (socket) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("end", function () {
|
socket.addListener("end", function () {
|
||||||
socket.close();
|
socket.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ client.addListener("timeout", function () {
|
|||||||
|
|
||||||
client.addListener("end", function () {
|
client.addListener("end", function () {
|
||||||
puts("client end");
|
puts("client end");
|
||||||
client.close();
|
client.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.addListener("close", function () {
|
client.addListener("close", function () {
|
||||||
|
@ -37,7 +37,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
|
|||||||
|
|
||||||
socket.addListener("end", function () {
|
socket.addListener("end", function () {
|
||||||
assert.equal("writeOnly", socket.readyState);
|
assert.equal("writeOnly", socket.readyState);
|
||||||
socket.close();
|
socket.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("close", function (had_error) {
|
socket.addListener("close", function (had_error) {
|
||||||
@ -83,7 +83,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
|
|||||||
} else {
|
} else {
|
||||||
sent_final_ping = true;
|
sent_final_ping = true;
|
||||||
client.write("PING");
|
client.write("PING");
|
||||||
client.close();
|
client.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ child.stdout.addListener("data", function (data){
|
|||||||
} else {
|
} else {
|
||||||
assert.equal("echo me\r\n", data);
|
assert.equal("echo me\r\n", data);
|
||||||
gotEcho = true;
|
gotEcho = true;
|
||||||
child.stdin.close();
|
child.stdin.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ var cat = spawn("cat");
|
|||||||
cat.stdin.write("hello");
|
cat.stdin.write("hello");
|
||||||
cat.stdin.write(" ");
|
cat.stdin.write(" ");
|
||||||
cat.stdin.write("world");
|
cat.stdin.write("world");
|
||||||
cat.stdin.close();
|
cat.stdin.end();
|
||||||
|
|
||||||
var response = "";
|
var response = "";
|
||||||
var exitStatus = -1;
|
var exitStatus = -1;
|
||||||
|
@ -10,7 +10,7 @@ var
|
|||||||
open: -1,
|
open: -1,
|
||||||
end: -1,
|
end: -1,
|
||||||
close: -1,
|
close: -1,
|
||||||
forceClose: -1
|
destroy: -1
|
||||||
},
|
},
|
||||||
|
|
||||||
paused = false,
|
paused = false,
|
||||||
@ -51,9 +51,9 @@ file
|
|||||||
});
|
});
|
||||||
|
|
||||||
var file2 = fs.createReadStream(fn);
|
var file2 = fs.createReadStream(fn);
|
||||||
file2.forceClose(function(err) {
|
file2.destroy(function(err) {
|
||||||
assert.ok(!err);
|
assert.ok(!err);
|
||||||
callbacks.forceClose++;
|
callbacks.destroy++;
|
||||||
});
|
});
|
||||||
|
|
||||||
process.addListener('exit', function() {
|
process.addListener('exit', function() {
|
||||||
|
@ -12,7 +12,7 @@ var
|
|||||||
open: -1,
|
open: -1,
|
||||||
drain: -2,
|
drain: -2,
|
||||||
close: -1,
|
close: -1,
|
||||||
closeCb: -1,
|
endCb: -1,
|
||||||
write: -11,
|
write: -11,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,9 +31,9 @@ file
|
|||||||
file.write(EXPECTED);
|
file.write(EXPECTED);
|
||||||
} else if (callbacks.drain == 0) {
|
} else if (callbacks.drain == 0) {
|
||||||
assert.equal(EXPECTED+EXPECTED, fs.readFileSync(fn));
|
assert.equal(EXPECTED+EXPECTED, fs.readFileSync(fn));
|
||||||
file.close(function(err) {
|
file.end(function(err) {
|
||||||
assert.ok(!err);
|
assert.ok(!err);
|
||||||
callbacks.closeCb++;
|
callbacks.endCb++;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -8,7 +8,7 @@ var client_got_eof = false;
|
|||||||
|
|
||||||
var server = http.createServer(function (req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
res.writeHead(200, {"Content-Type": "text/plain"});
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
||||||
res.close(body);
|
res.end(body);
|
||||||
})
|
})
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ c.addListener("data", function (chunk) {
|
|||||||
|
|
||||||
c.addListener("end", function () {
|
c.addListener("end", function () {
|
||||||
client_got_eof = true;
|
client_got_eof = true;
|
||||||
c.close();
|
c.end();
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ var server = http.createServer(function (req, res) {
|
|||||||
["Content-Length", body.length],
|
["Content-Length", body.length],
|
||||||
["Content-Type", "text/plain"]
|
["Content-Type", "text/plain"]
|
||||||
]);
|
]);
|
||||||
res.close(body);
|
res.end(body);
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ var UTF8_STRING = "南越国是前203年至前111年存在于岭南地区的一
|
|||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function(req, res) {
|
||||||
res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
|
res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
|
||||||
res.close(UTF8_STRING, 'utf8');
|
res.end(UTF8_STRING, 'utf8');
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ var server = http.createServer(function (req, res) {
|
|||||||
res.writeHead(200, { "Content-Type": "text/plain"
|
res.writeHead(200, { "Content-Type": "text/plain"
|
||||||
, "Content-Length": body.length
|
, "Content-Length": body.length
|
||||||
});
|
});
|
||||||
res.close(body);
|
res.end(body);
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
@ -34,10 +34,10 @@ req1.addListener('response', function (res1) {
|
|||||||
res2.addListener('data', function (chunk) { body2 += chunk; });
|
res2.addListener('data', function (chunk) { body2 += chunk; });
|
||||||
res2.addListener('end', function () { server.close(); });
|
res2.addListener('end', function () { server.close(); });
|
||||||
});
|
});
|
||||||
req2.close();
|
req2.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
req1.close();
|
req1.end();
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
assert.equal(body1_s, body1);
|
assert.equal(body1_s, body1);
|
||||||
|
@ -19,7 +19,7 @@ var server = http.createServer(function(req, res) {
|
|||||||
puts("request complete from server");
|
puts("request complete from server");
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||||
res.write('hello\n');
|
res.write('hello\n');
|
||||||
res.close();
|
res.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
@ -42,7 +42,7 @@ req.addListener('response', function(res) {
|
|||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
req.close();
|
req.end();
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
assert.equal("1\n2\n3\n", sent_body);
|
assert.equal("1\n2\n3\n", sent_body);
|
||||||
|
@ -14,7 +14,7 @@ var s = http.createServer(function (req, res) {
|
|||||||
|
|
||||||
res.writeHead(200, {"Content-Type": "text/plain"});
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
||||||
res.write("Hello World");
|
res.write("Hello World");
|
||||||
res.close();
|
res.end();
|
||||||
|
|
||||||
if (++nrequests_completed == nrequests_expected) s.close();
|
if (++nrequests_completed == nrequests_expected) s.close();
|
||||||
});
|
});
|
||||||
@ -23,7 +23,7 @@ s.listen(PORT);
|
|||||||
var c = net.createConnection(PORT);
|
var c = net.createConnection(PORT);
|
||||||
c.addListener("connect", function () {
|
c.addListener("connect", function () {
|
||||||
c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
|
c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
|
||||||
c.close();
|
c.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO add more!
|
// TODO add more!
|
||||||
|
@ -9,7 +9,7 @@ var backend = http.createServer(function (req, res) {
|
|||||||
debug("backend request");
|
debug("backend request");
|
||||||
res.writeHead(200, {"content-type": "text/plain"});
|
res.writeHead(200, {"content-type": "text/plain"});
|
||||||
res.write("hello world\n");
|
res.write("hello world\n");
|
||||||
res.close();
|
res.end();
|
||||||
});
|
});
|
||||||
debug("listen backend")
|
debug("listen backend")
|
||||||
backend.listen(BACKEND_PORT);
|
backend.listen(BACKEND_PORT);
|
||||||
@ -24,11 +24,11 @@ var proxy = http.createServer(function (req, res) {
|
|||||||
res.write(chunk);
|
res.write(chunk);
|
||||||
});
|
});
|
||||||
proxy_res.addListener("end", function() {
|
proxy_res.addListener("end", function() {
|
||||||
res.close();
|
res.end();
|
||||||
debug("proxy res");
|
debug("proxy res");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
proxy_req.close();
|
proxy_req.end();
|
||||||
});
|
});
|
||||||
debug("listen proxy")
|
debug("listen proxy")
|
||||||
proxy.listen(PROXY_PORT);
|
proxy.listen(PROXY_PORT);
|
||||||
@ -54,7 +54,7 @@ function startReq () {
|
|||||||
debug("closed both");
|
debug("closed both");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
req.close();
|
req.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy.addListener('listening', startReq);
|
proxy.addListener('listening', startReq);
|
||||||
|
@ -38,7 +38,7 @@ http.createServer(function (req, res) {
|
|||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
res.writeHead(200, {"Content-Type": "text/plain"});
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
||||||
res.write(url.parse(req.url).pathname);
|
res.write(url.parse(req.url).pathname);
|
||||||
res.close();
|
res.end();
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
}).listen(PORT);
|
}).listen(PORT);
|
||||||
@ -63,7 +63,7 @@ c.addListener("data", function (chunk) {
|
|||||||
if (requests_sent == 2) {
|
if (requests_sent == 2) {
|
||||||
c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n"
|
c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n"
|
||||||
+"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n");
|
+"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n");
|
||||||
c.close();
|
c.end();
|
||||||
assert.equal(c.readyState, "readOnly");
|
assert.equal(c.readyState, "readOnly");
|
||||||
requests_sent += 2;
|
requests_sent += 2;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ var http_server=http.createServer(function (req, res) {
|
|||||||
req.addListener('end', function () {
|
req.addListener('end', function () {
|
||||||
res.writeHead(200, {"Content-Type": "text/plain"});
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
||||||
res.write("The path was " + url.parse(req.url).pathname);
|
res.write("The path was " + url.parse(req.url).pathname);
|
||||||
res.close();
|
res.end();
|
||||||
responses_sent += 1;
|
responses_sent += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ req.addListener('response', function (res) {
|
|||||||
res.addListener('data', function (chunk) { body0 += chunk; });
|
res.addListener('data', function (chunk) { body0 += chunk; });
|
||||||
debug("Got /hello response");
|
debug("Got /hello response");
|
||||||
});
|
});
|
||||||
req.close();
|
req.end();
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
req = client.request("POST", "/world");
|
req = client.request("POST", "/world");
|
||||||
@ -94,7 +94,7 @@ setTimeout(function () {
|
|||||||
res.addListener('data', function (chunk) { body1 += chunk; });
|
res.addListener('data', function (chunk) { body1 += chunk; });
|
||||||
debug("Got /world response");
|
debug("Got /world response");
|
||||||
});
|
});
|
||||||
req.close();
|
req.end();
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
|
@ -25,7 +25,7 @@ var server = http.createServer(function (req, res) {
|
|||||||
res.writeHead(200, {"Content-Type": "text/plain"});
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
||||||
res.write("hello ");
|
res.write("hello ");
|
||||||
res.write("world\n");
|
res.write("world\n");
|
||||||
res.close();
|
res.end();
|
||||||
})
|
})
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ c.addListener("data", function (chunk) {
|
|||||||
c.addListener("end", function () {
|
c.addListener("end", function () {
|
||||||
client_got_eof = true;
|
client_got_eof = true;
|
||||||
puts('got end');
|
puts('got end');
|
||||||
c.close();
|
c.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
c.addListener("close", function () {
|
c.addListener("close", function () {
|
||||||
|
@ -29,7 +29,7 @@ http.createServer(function (req, res) {
|
|||||||
req.addListener('end', function () {
|
req.addListener('end', function () {
|
||||||
res.writeHead(200, {"Content-Type": "text/plain"});
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
||||||
res.write("The path was " + url.parse(req.url).pathname);
|
res.write("The path was " + url.parse(req.url).pathname);
|
||||||
res.close();
|
res.end();
|
||||||
responses_sent += 1;
|
responses_sent += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ req.addListener('response', function (res) {
|
|||||||
res.addListener('data', function (chunk) { body0 += chunk; });
|
res.addListener('data', function (chunk) { body0 += chunk; });
|
||||||
debug("Got /hello response");
|
debug("Got /hello response");
|
||||||
});
|
});
|
||||||
req.close();
|
req.end();
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
req = client.request("POST", "/world");
|
req = client.request("POST", "/world");
|
||||||
@ -56,7 +56,7 @@ setTimeout(function () {
|
|||||||
res.addListener('data', function (chunk) { body1 += chunk; });
|
res.addListener('data', function (chunk) { body1 += chunk; });
|
||||||
debug("Got /world response");
|
debug("Got /world response");
|
||||||
});
|
});
|
||||||
req.close();
|
req.end();
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
|
@ -30,7 +30,7 @@ function pingPongTest (port, host) {
|
|||||||
socket.addListener("end", function () {
|
socket.addListener("end", function () {
|
||||||
assert.equal(true, socket.writable);
|
assert.equal(true, socket.writable);
|
||||||
assert.equal(false, socket.readable);
|
assert.equal(false, socket.readable);
|
||||||
socket.close();
|
socket.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("error", function (e) {
|
socket.addListener("error", function (e) {
|
||||||
@ -38,7 +38,7 @@ function pingPongTest (port, host) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("close", function () {
|
socket.addListener("close", function () {
|
||||||
puts('server socket closed');
|
puts('server socket.endd');
|
||||||
assert.equal(false, socket.writable);
|
assert.equal(false, socket.writable);
|
||||||
assert.equal(false, socket.readable);
|
assert.equal(false, socket.readable);
|
||||||
socket.server.close();
|
socket.server.close();
|
||||||
@ -77,12 +77,12 @@ function pingPongTest (port, host) {
|
|||||||
} else {
|
} else {
|
||||||
sent_final_ping = true;
|
sent_final_ping = true;
|
||||||
client.write("PING");
|
client.write("PING");
|
||||||
client.close();
|
client.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.addListener("close", function () {
|
client.addListener("close", function () {
|
||||||
puts('client closed');
|
puts('client.endd');
|
||||||
assert.equal(N+1, count);
|
assert.equal(N+1, count);
|
||||||
assert.equal(true, sent_final_ping);
|
assert.equal(true, sent_final_ping);
|
||||||
tests_run += 1;
|
tests_run += 1;
|
||||||
|
@ -12,7 +12,7 @@ var server = http.createServer(function(req, res) {
|
|||||||
|
|
||||||
res.writeHead(200, {'Content-Type': 'text/javascript'});
|
res.writeHead(200, {'Content-Type': 'text/javascript'});
|
||||||
res.write(body);
|
res.write(body);
|
||||||
res.close();
|
res.end();
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ var echoServer = tcp.createServer(function (connection) {
|
|||||||
connection.write(chunk, "binary");
|
connection.write(chunk, "binary");
|
||||||
});
|
});
|
||||||
connection.addListener("end", function () {
|
connection.addListener("end", function () {
|
||||||
connection.close();
|
connection.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
echoServer.listen(PORT);
|
echoServer.listen(PORT);
|
||||||
@ -42,7 +42,7 @@ c.addListener("data", function (chunk) {
|
|||||||
c.write(String.fromCharCode(j), "binary");
|
c.write(String.fromCharCode(j), "binary");
|
||||||
j++;
|
j++;
|
||||||
} else {
|
} else {
|
||||||
c.close();
|
c.end();
|
||||||
}
|
}
|
||||||
recv += chunk;
|
recv += chunk;
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,7 @@ var server = net.createServer(function (socket) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("end", function () {
|
socket.addListener("end", function () {
|
||||||
socket.close();
|
socket.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.addListener("close", function (had_error) {
|
socket.addListener("close", function (had_error) {
|
||||||
@ -37,7 +37,7 @@ server.addListener('listening', function () {
|
|||||||
client_recv_count += 1;
|
client_recv_count += 1;
|
||||||
puts("client_recv_count " + client_recv_count);
|
puts("client_recv_count " + client_recv_count);
|
||||||
assert.equal("hello\r\n", chunk);
|
assert.equal("hello\r\n", chunk);
|
||||||
client.close();
|
client.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.addListener("close", function (had_error) {
|
client.addListener("close", function (had_error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user