Revision c024d2d8

View differences:

lib/_stream_readable.js
400 400

  
401 401
  function cleanup() {
402 402
    // cleanup event handlers once the pipe is broken
403
    dest.removeListener('close', unpipe);
403
    dest.removeListener('close', onclose);
404 404
    dest.removeListener('finish', onfinish);
405 405
    dest.removeListener('drain', ondrain);
406 406
    dest.removeListener('error', onerror);
......
426 426
  }
427 427
  dest.once('error', onerror);
428 428

  
429
  // if the dest emits close, then presumably there's no point writing
430
  // to it any more.
431
  dest.once('close', unpipe);
429
  // Both close and finish should trigger unpipe, but only once.
430
  function onclose() {
431
    dest.removeListener('finish', onfinish);
432
    unpipe();
433
  }
434
  dest.once('close', onclose);
432 435
  function onfinish() {
433
    dest.removeListener('close', unpipe);
436
    dest.removeListener('close', onclose);
437
    unpipe();
434 438
  }
435 439
  dest.once('finish', onfinish);
436 440

  
test/simple/test-stream2-finish-pipe.js
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.js');
23
var stream = require('stream');
24
var Buffer = require('buffer').Buffer;
25

  
26
var R = new stream.Readable();
27
R._read = function(size, cb) {
28
  cb(null, new Buffer(size));
29
};
30

  
31
var W = new stream.Writable();
32
W._write = function(data, cb) {
33
  cb(null);
34
};
35

  
36
R.pipe(W);
37

  
38
// This might sound unrealistic, but it happens in net.js. When
39
// `socket.allowHalfOpen === false`, EOF will cause `.destroySoon()` call which
40
// ends the writable side of net.Socket.
41
W.end();

Also available in: Unified diff