Skip to content
This repository
Browse code

net.Socket: Delay pause/resume until after connect

Fix #3118
  • Loading branch information...
commit de65ba7aba0e48a846e8cad86278f51372d3de23 1 parent 196207c
Isaac Z. Schlueter authored
18  lib/net.js
@@ -236,6 +236,12 @@ Object.defineProperty(Socket.prototype, 'bufferSize', {
236 236
 
237 237
 
238 238
 Socket.prototype.pause = function() {
  239
+  if (this._paused) return;
  240
+  this._paused = true;
  241
+  if (this._connecting) {
  242
+    // will actually pause once the handle is established.
  243
+    return;
  244
+  }
239 245
   if (this._handle) {
240 246
     this._handle.readStop();
241 247
   }
@@ -243,6 +249,12 @@ Socket.prototype.pause = function() {
243 249
 
244 250
 
245 251
 Socket.prototype.resume = function() {
  252
+  if (!this._paused) return;
  253
+  this._paused = false;
  254
+  if (this._connecting) {
  255
+    // will actually resume once the handle is established.
  256
+    return;
  257
+  }
246 258
   if (this._handle) {
247 259
     this._handle.readStart();
248 260
   }
@@ -733,6 +745,12 @@ function afterConnect(status, handle, req, readable, writable) {
733 745
   assert.ok(self._connecting);
734 746
   self._connecting = false;
735 747
 
  748
+  // now that we're connected, process any pending pause state.
  749
+  if (self._paused) {
  750
+    self._paused = false;
  751
+    self.pause();
  752
+  }
  753
+
736 754
   if (status == 0) {
737 755
     self.readable = readable;
738 756
     self.writable = writable;
30  test/simple/test-net-socket-pause-resume-immediate.js
... ...
@@ -0,0 +1,30 @@
  1
+// Copyright Joyent, Inc. and other Node contributors.
  2
+//
  3
+// Permission is hereby granted, free of charge, to any person obtaining a
  4
+// copy of this software and associated documentation files (the
  5
+// "Software"), to deal in the Software without restriction, including
  6
+// without limitation the rights to use, copy, modify, merge, publish,
  7
+// distribute, sublicense, and/or sell copies of the Software, and to permit
  8
+// persons to whom the Software is furnished to do so, subject to the
  9
+// following conditions:
  10
+//
  11
+// The above copyright notice and this permission notice shall be included
  12
+// in all copies or substantial portions of the Software.
  13
+//
  14
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
  21
+
  22
+var common = require('../common');
  23
+var assert = require('assert');
  24
+var net = require('net');
  25
+
  26
+var sock = net.connect(1234, 'localhost');
  27
+sock.pause();
  28
+sock.resume();
  29
+console.log('ok');
  30
+process.exit(0);

0 notes on commit de65ba7

Please sign in to comment.
Something went wrong with that request. Please try again.