Permalink
Browse files

Don't flush net writeQueue on end() if its still connecting

  • Loading branch information...
1 parent 97e3040 commit 13dba0d1c1f00c29db59db3c64e754ae6b24ff10 @josh josh committed with ry Oct 12, 2010
Showing with 50 additions and 1 deletion.
  1. +3 −1 lib/net.js
  2. +47 −0 test/simple/test-net-connect-buffer.js
View
@@ -1042,7 +1042,9 @@ Stream.prototype.end = function (data, encoding) {
if (data) this.write(data, encoding);
if (this._writeQueueLast() !== END_OF_FILE) {
this._writeQueue.push(END_OF_FILE);
- this.flush();
+ if (!this._connecting) {
+ this.flush();
+ }
}
}
};
@@ -0,0 +1,47 @@
+var common = require('../common');
+var assert = require('assert');
+var net = require('net');
+
+var tcpPort = common.PORT;
+
+var tcp = net.Server(function (s) {
+ tcp.close();
+
+ console.log("tcp server connection");
+
+ var buf = "";
+ s.on('data', function (d) {
+ buf += d;
+ });
+
+ s.on('end', function () {
+ assert.equal("foobar", buf);
+ console.log("tcp socket disconnect");
+ s.end();
+ });
+
+ s.on('error', function (e) {
+ console.log("tcp server-side error: " + e.message);
+ process.exit(1);
+ });
+});
+tcp.listen(tcpPort, startClient);
+
+function startClient () {
+ var socket = net.Stream();
+
+ console.log("Connecting to socket");
+
+ socket.connect(tcpPort);
+
+ socket.on('connect', function () {
+ console.log('socket connected');
+ });
+
+ assert.equal("opening", socket.readyState);
+
+ assert.equal(false, socket.write("foo"));
+ socket.end("bar");
+
+ assert.equal("opening", socket.readyState);
+}

0 comments on commit 13dba0d

Please sign in to comment.