Skip to content

Commit 577b126

Browse files
committed
Move end() logic to Buffer and simplify its logic
1 parent c386013 commit 577b126

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

Datagram/Buffer.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Buffer extends EventEmitter
1212
private $socket;
1313
private $listening = false;
1414
private $outgoing = array();
15+
private $writable = true;
1516

1617
public function __construct(LoopInterface $loop, $socket)
1718
{
@@ -21,7 +22,7 @@ public function __construct(LoopInterface $loop, $socket)
2122

2223
public function send($data, $remoteAddress = null)
2324
{
24-
if ($this->socket === false) {
25+
if ($this->writable === false) {
2526
return;
2627
}
2728

@@ -70,13 +71,22 @@ public function close()
7071
$this->listening = false;
7172
}
7273

74+
$this->writable = false;
7375
$this->socket = false;
7476
$this->outgoing = array();
7577
$this->removeAllListeners();
7678
}
7779

7880
public function end()
7981
{
82+
if ($this->writable === false) {
83+
return;
84+
}
8085

86+
$this->writable = false;
87+
88+
if (!$this->listening) {
89+
$this->close();
90+
}
8191
}
8292
}

Datagram/Socket.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class Socket extends EventEmitter implements SocketInterface
1111
protected $socket;
1212

1313
protected $buffer;
14-
protected $writable = true;
1514

1615
public $bufferSize = 65536;
1716

@@ -94,7 +93,6 @@ public function close()
9493
$this->pause();
9594

9695
fclose($this->socket);
97-
$this->writable = false;
9896
$this->socket = false;
9997
$this->buffer->close();
10098

@@ -103,18 +101,6 @@ public function close()
103101

104102
public function end()
105103
{
106-
if (!$this->writable) {
107-
return;
108-
}
109-
110-
$this->writable = false;
111-
112-
$that = $this;
113-
114-
$this->buffer->on('close', function () use ($that) {
115-
$that->close();
116-
});
117-
118104
$this->buffer->end();
119105
}
120106

Datagram/SocketInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* @event message($data, $remoteAddress, $thisSocket)
1111
* @event error($exception, $thisSocket)
1212
* @event close($thisSocket)
13-
* @event end($thisSocket);
1413
*/
1514
interface SocketInterface extends EventEmitterInterface
1615
{

0 commit comments

Comments
 (0)