|
2 | 2 |
|
3 | 3 | namespace React\Socket; |
4 | 4 |
|
5 | | -use React\Stream\Stream; |
6 | | -use React\EventLoop\LoopInterface; |
7 | 5 | use Evenement\EventEmitter; |
| 6 | +use React\EventLoop\LoopInterface; |
| 7 | +use React\Stream\DuplexResourceStream; |
| 8 | +use React\Stream\Stream; |
8 | 9 | use React\Stream\Util; |
9 | 10 | use React\Stream\WritableStreamInterface; |
10 | 11 |
|
@@ -35,23 +36,33 @@ class Connection extends EventEmitter implements ConnectionInterface |
35 | 36 |
|
36 | 37 | public function __construct($resource, LoopInterface $loop) |
37 | 38 | { |
38 | | - $this->input = new Stream($resource, $loop); |
39 | | - $this->stream = $resource; |
40 | | - |
41 | | - Util::forwardEvents($this->input, $this, array('data', 'end', 'error', 'close', 'pipe', 'drain')); |
42 | | - |
43 | | - $this->input->on('close', array($this, 'close')); |
44 | | - |
45 | 39 | // PHP < 5.6.8 suffers from a buffer indicator bug on secure TLS connections |
46 | 40 | // as a work-around we always read the complete buffer until its end. |
47 | 41 | // The buffer size is limited due to TCP/IP buffers anyway, so this |
48 | 42 | // should not affect usage otherwise. |
49 | 43 | // See https://bugs.php.net/bug.php?id=65137 |
50 | 44 | // https://bugs.php.net/bug.php?id=41631 |
51 | 45 | // https://github.com/reactphp/socket-client/issues/24 |
52 | | - if (version_compare(PHP_VERSION, '5.6.8', '<')) { |
53 | | - $this->input->bufferSize = null; |
| 46 | + $clearCompleteBuffer = (version_compare(PHP_VERSION, '5.6.8', '<')); |
| 47 | + |
| 48 | + // @codeCoverageIgnoreStart |
| 49 | + if (class_exists('React\Stream\Stream')) { |
| 50 | + // legacy react/stream < 0.7 requires additional buffer property |
| 51 | + $this->input = new Stream($resource, $loop); |
| 52 | + if ($clearCompleteBuffer) { |
| 53 | + $this->input->bufferSize = null; |
| 54 | + } |
| 55 | + } else { |
| 56 | + // preferred react/stream >= 0.7 accepts buffer parameter |
| 57 | + $this->input = new DuplexResourceStream($resource, $loop, $clearCompleteBuffer ? -1 : null); |
54 | 58 | } |
| 59 | + // @codeCoverageIgnoreEnd |
| 60 | + |
| 61 | + $this->stream = $resource; |
| 62 | + |
| 63 | + Util::forwardEvents($this->input, $this, array('data', 'end', 'error', 'close', 'pipe', 'drain')); |
| 64 | + |
| 65 | + $this->input->on('close', array($this, 'close')); |
55 | 66 | } |
56 | 67 |
|
57 | 68 | public function isReadable() |
|
0 commit comments