Skip to content

Commit c386013

Browse files
committed
Add skeleton for end() method
1 parent 9c53070 commit c386013

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Datagram/Buffer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,9 @@ public function close()
7474
$this->outgoing = array();
7575
$this->removeAllListeners();
7676
}
77+
78+
public function end()
79+
{
80+
81+
}
7782
}

Datagram/Socket.php

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

1313
protected $buffer;
14+
protected $writable = true;
1415

1516
public $bufferSize = 65536;
1617

@@ -93,12 +94,30 @@ public function close()
9394
$this->pause();
9495

9596
fclose($this->socket);
97+
$this->writable = false;
9698
$this->socket = false;
9799
$this->buffer->close();
98100

99101
$this->removeAllListeners();
100102
}
101103

104+
public function end()
105+
{
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+
118+
$this->buffer->end();
119+
}
120+
102121
private function sanitizeAddress($address)
103122
{
104123
// doc comment suggests IPv6 address is not enclosed in square brackets?

Datagram/SocketInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
* @event message($data, $remoteAddress, $thisSocket)
1111
* @event error($exception, $thisSocket)
1212
* @event close($thisSocket)
13+
* @event end($thisSocket);
1314
*/
1415
interface SocketInterface extends EventEmitterInterface
1516
{
1617
public function send($data, $remoteAddress = null);
1718

1819
public function close();
1920

21+
public function end();
22+
2023
public function resume();
2124

2225
public function pause();

0 commit comments

Comments
 (0)