path = require("path");
var puts = require("sys").puts;
-var old = true;
+var old = false;
http = require(old ? "http_old" : 'http');
if (old) puts('old version');
res.write(body, 'ascii');
res.close();
} else {
- res.close(body, 'ascii');
+ res.end(body, 'ascii');
}
}).listen(8000);
if (bytesRead === 0) {
self.emit('end');
- self.forceClose();
+ self.destroy();
return;
}
};
+var readStreamForceCloseWarning;
+
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;
this.readable = false;
};
+var writeStreamCloseWarning;
+
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._queue.push([fs.close, cb]);
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) {
this.writeable = false;
fs.close(self.fd, function(err) {
throw new Error("finish() has been renamed to close().");
};
+var closeWarning;
+
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 (this.chunkedEncoding) this._send("0\r\n\r\n"); // last chunk
this.finished = true;
exports.ClientRequest = ClientRequest;
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 "
+ "to the request object."
);
};
+var clientRequestCloseWarning;
+
ClientRequest.prototype.close = function () {
+ if (!clientRequestCloseWarning) {
+ clientRequestCloseWarning = "Warning: ClientRequest.prototype.close has been renamed to end()";
+ sys.error(clientRequestCloseWarning);
+ }
+ if (arguments.length > 0) {
+ throw new Error( "ClientRequest.prototype.end does not take any arguments. "
+ + "Add a response listener manually to the request object."
+ );
+ }
+ return this.end();
+};
+
+ClientRequest.prototype.end = function () {
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."
);
}
- OutgoingMessage.prototype.close.call(this);
+ OutgoingMessage.prototype.end.call(this);
};
freeParser(parser);
if (responses.length == 0) {
- socket.close();
+ socket.end();
} else {
responses[responses.length-1].closeOnFinish = true;
}
res.shouldKeepAlive = shouldKeepAlive;
res.addListener('flush', function () {
if (flushMessageQueue(socket, responses)) {
- socket.close();
+ socket.end();
}
});
responses.push(res);
parser.finish();
debug("self got end closing. readyState = " + self.readyState);
- self.close();
+ self.end();
});
self.addListener("close", function (e) {
res.addListener('end', function ( ) {
debug("request complete disconnecting. readyState = " + self.readyState);
- self.close();
+ self.end();
});
currentRequest.emit("response", res);
req.addListener('response', function (res) {
if (res.statusCode < 200 || res.statusCode >= 300) {
if (callback) callback(res.statusCode);
- client.close();
+ client.end();
return;
}
res.setBodyEncoding(encoding);
if (callback) callback(err);
});
- req.close();
+ req.end();
};
remove(first);
assert(first != peek(list));
first.emit('timeout');
- first.forceClose(new Error('idle timeout'));
+ first.destroy(new Error('idle timeout'));
}
}
debug(msecs + ' list empty');
pool.used,
pool.length - pool.used);
} catch (e) {
- self.forceClose(e);
+ self.destroy(e);
return;
}
if (self._events && self._events['end']) self.emit('end');
if (self.onend) self.onend();
- if (!self.writable) self.forceClose();
+ if (!self.writable) self.destroy();
} else if (bytesRead > 0) {
timeout.active(self);
try {
bytesWritten = write(this.fd, buffer, off, len);
} catch (e) {
- this.forceClose(e);
+ this.destroy(e);
return false;
}
try {
connect(socket.fd, port, host);
} catch (e) {
- socket.forceClose(e);
+ socket.destroy(e);
return;
}
socket._writeWatcher.callback = _doFlush;
socket.emit('connect');
} else if (errno != EINPROGRESS) {
- socket.forceClose(errnoException(errno, 'connect'));
+ socket.destroy(errnoException(errno, 'connect'));
}
};
}
};
-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.
var self = this;
try {
shutdown(this.fd, 'write')
} catch (e) {
- this.forceClose(e);
+ this.destroy(e);
return;
}
- if (!this.readable) this.forceClose();
+ if (!this.readable) this.destroy();
}
};
+var closeDepricationWarning;
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 (data) this.write(data, encoding);
if (this._writeQueueLast() != END_OF_FILE) {
this._writeQueue.push(END_OF_FILE);
this.flush();
var eofCount = 0;
var server = tcp.createServer(function(socket) {
- socket.close();
+ socket.end();
});
server.listen(PORT);
request.addListener('response', function(response) {
sys.puts("STATUS: " + response.statusCode);
});
-request.close();
+request.end();
setTimeout(function () {
server.close();
"Content-Type": "text/plain",
});
res.write(body);
- res.close();
+ res.end();
});
server.listen(PORT);
total_connections++;
print("#");
c.write(body);
- c.close();
+ c.end();
});
});
server.listen(PORT);
});
client.addListener("end", function () {
- client.close();
+ client.end();
});
client.addListener("error", function (e) {
server = net.createServer(function (connection) {
function write (j) {
if (j >= N) {
- connection.close();
+ connection.end();
return;
}
setTimeout(function () {
client.addListener("end", function () {
server.close();
- client.close();
+ client.end();
});
process.addListener("exit", function () {
var N = 100;
var DELAY = 1;
var count = 0;
- var client_closed = false;
+ var client_ended = false;
var server = net.createServer(function (socket) {
socket.setEncoding("utf8");
socket.addListener("end", function () {
puts("server-side socket EOF");
assert.equal("writeOnly", socket.readyState);
- socket.close();
+ socket.end();
});
socket.addListener("close", function (had_error) {
- puts("server-side socket close");
+ puts("server-side socket.end");
assert.equal(false, had_error);
assert.equal("closed", socket.readyState);
socket.server.close();
client.write("PING");
} else {
puts("closing client");
- client.close();
- client_closed = true;
+ client.end();
+ client_ended = true;
}
}, DELAY);
});
});
client.addListener("close", function () {
- puts("client close");
+ puts("client.end");
assert.equal(N+1, count);
- assert.equal(true, client_closed);
+ assert.ok(client_ended);
if (on_complete) on_complete();
tests_run += 1;
});
socket.addListener("end", function () {
assert.equal("writeOnly", socket.readyState);
- socket.close();
+ socket.end();
});
socket.addListener("close", function (had_error) {
} else {
sent_final_ping = true;
client.write("PING");
- client.close();
+ client.end();
}
});
server = net.createServer(function (connection) {
connection.addListener("connect", function () {
assert.equal(false, connection.write(body));
- connection.close();
+ connection.end();
});
});
server.listen(PORT);
client.addListener("end", function () {
server.close();
- client.close();
+ client.end();
});
process.addListener("exit", function () {
});
socket.addListener("end", function () {
- socket.close();
+ socket.end();
});
});
client.addListener("end", function () {
puts("client end");
- client.close();
+ client.end();
});
client.addListener("close", function () {
socket.addListener("end", function () {
assert.equal("writeOnly", socket.readyState);
- socket.close();
+ socket.end();
});
socket.addListener("close", function (had_error) {
} else {
sent_final_ping = true;
client.write("PING");
- client.close();
+ client.end();
}
});
} else {
assert.equal("echo me\r\n", data);
gotEcho = true;
- child.stdin.close();
+ child.stdin.end();
}
});
cat.stdin.write("hello");
cat.stdin.write(" ");
cat.stdin.write("world");
-cat.stdin.close();
+cat.stdin.end();
var response = "";
var exitStatus = -1;
open: -1,
end: -1,
close: -1,
- forceClose: -1
+ destroy: -1
},
paused = false,
});
var file2 = fs.createReadStream(fn);
-file2.forceClose(function(err) {
+file2.destroy(function(err) {
assert.ok(!err);
- callbacks.forceClose++;
+ callbacks.destroy++;
});
process.addListener('exit', function() {
open: -1,
drain: -2,
close: -1,
- closeCb: -1,
+ endCb: -1,
write: -11,
};
file.write(EXPECTED);
} else if (callbacks.drain == 0) {
assert.equal(EXPECTED+EXPECTED, fs.readFileSync(fn));
- file.close(function(err) {
+ file.end(function(err) {
assert.ok(!err);
- callbacks.closeCb++;
+ callbacks.endCb++;
});
}
})
var server = http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"});
- res.close(body);
+ res.end(body);
})
server.listen(PORT);
c.addListener("end", function () {
client_got_eof = true;
- c.close();
+ c.end();
server.close();
});
["Content-Length", body.length],
["Content-Type", "text/plain"]
]);
- res.close(body);
+ res.end(body);
});
server.listen(PORT);
var server = http.createServer(function(req, res) {
res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
- res.close(UTF8_STRING, 'utf8');
+ res.end(UTF8_STRING, 'utf8');
});
server.listen(PORT);
res.writeHead(200, { "Content-Type": "text/plain"
, "Content-Length": body.length
});
- res.close(body);
+ res.end(body);
});
server.listen(PORT);
res2.addListener('data', function (chunk) { body2 += chunk; });
res2.addListener('end', function () { server.close(); });
});
- req2.close();
+ req2.end();
});
});
-req1.close();
+req1.end();
process.addListener("exit", function () {
assert.equal(body1_s, body1);
puts("request complete from server");
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('hello\n');
- res.close();
+ res.end();
});
});
server.listen(PORT);
server.close();
});
});
-req.close();
+req.end();
process.addListener("exit", function () {
assert.equal("1\n2\n3\n", sent_body);
res.writeHead(200, {"Content-Type": "text/plain"});
res.write("Hello World");
- res.close();
+ res.end();
if (++nrequests_completed == nrequests_expected) s.close();
});
var c = net.createConnection(PORT);
c.addListener("connect", function () {
c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
- c.close();
+ c.end();
});
// TODO add more!
debug("backend request");
res.writeHead(200, {"content-type": "text/plain"});
res.write("hello world\n");
- res.close();
+ res.end();
});
debug("listen backend")
backend.listen(BACKEND_PORT);
res.write(chunk);
});
proxy_res.addListener("end", function() {
- res.close();
+ res.end();
debug("proxy res");
});
});
- proxy_req.close();
+ proxy_req.end();
});
debug("listen proxy")
proxy.listen(PROXY_PORT);
debug("closed both");
});
});
- req.close();
+ req.end();
}
proxy.addListener('listening', startReq);
setTimeout(function () {
res.writeHead(200, {"Content-Type": "text/plain"});
res.write(url.parse(req.url).pathname);
- res.close();
+ res.end();
}, 1);
}).listen(PORT);
if (requests_sent == 2) {
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");
- c.close();
+ c.end();
assert.equal(c.readyState, "readOnly");
requests_sent += 2;
}
req.addListener('end', function () {
res.writeHead(200, {"Content-Type": "text/plain"});
res.write("The path was " + url.parse(req.url).pathname);
- res.close();
+ res.end();
responses_sent += 1;
});
res.addListener('data', function (chunk) { body0 += chunk; });
debug("Got /hello response");
});
-req.close();
+req.end();
setTimeout(function () {
req = client.request("POST", "/world");
res.addListener('data', function (chunk) { body1 += chunk; });
debug("Got /world response");
});
- req.close();
+ req.end();
}, 1);
process.addListener("exit", function () {
res.writeHead(200, {"Content-Type": "text/plain"});
res.write("hello ");
res.write("world\n");
- res.close();
+ res.end();
})
server.listen(PORT);
c.addListener("end", function () {
client_got_eof = true;
puts('got end');
- c.close();
+ c.end();
});
c.addListener("close", function () {
req.addListener('end', function () {
res.writeHead(200, {"Content-Type": "text/plain"});
res.write("The path was " + url.parse(req.url).pathname);
- res.close();
+ res.end();
responses_sent += 1;
});
res.addListener('data', function (chunk) { body0 += chunk; });
debug("Got /hello response");
});
-req.close();
+req.end();
setTimeout(function () {
req = client.request("POST", "/world");
res.addListener('data', function (chunk) { body1 += chunk; });
debug("Got /world response");
});
- req.close();
+ req.end();
}, 1);
process.addListener("exit", function () {
socket.addListener("end", function () {
assert.equal(true, socket.writable);
assert.equal(false, socket.readable);
- socket.close();
+ socket.end();
});
socket.addListener("error", function (e) {
});
socket.addListener("close", function () {
- puts('server socket closed');
+ puts('server socket.endd');
assert.equal(false, socket.writable);
assert.equal(false, socket.readable);
socket.server.close();
} else {
sent_final_ping = true;
client.write("PING");
- client.close();
+ client.end();
}
});
client.addListener("close", function () {
- puts('client closed');
+ puts('client.endd');
assert.equal(N+1, count);
assert.equal(true, sent_final_ping);
tests_run += 1;
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.write(body);
- res.close();
+ res.end();
});
server.listen(PORT);
connection.write(chunk, "binary");
});
connection.addListener("end", function () {
- connection.close();
+ connection.end();
});
});
echoServer.listen(PORT);
c.write(String.fromCharCode(j), "binary");
j++;
} else {
- c.close();
+ c.end();
}
recv += chunk;
});
});
socket.addListener("end", function () {
- socket.close();
+ socket.end();
});
socket.addListener("close", function (had_error) {
client_recv_count += 1;
puts("client_recv_count " + client_recv_count);
assert.equal("hello\r\n", chunk);
- client.close();
+ client.end();
});
client.addListener("close", function (had_error) {