Skip to content

Commit ec9721b

Browse files
committed
Add Buffer::close() method
1 parent 8ad7e71 commit ec9721b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Datagram/Buffer.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public function __construct(LoopInterface $loop, $socket)
1919

2020
public function send($data, $remoteAddress = null)
2121
{
22+
if ($this->socket === false) {
23+
return;
24+
}
25+
2226
$this->outgoing []= array($data, $remoteAddress);
2327

2428
if (!$this->listening) {
@@ -42,4 +46,19 @@ public function handleWrite()
4246
$this->listening = false;
4347
}
4448
}
49+
50+
public function close()
51+
{
52+
if ($this->socket === false) {
53+
return false;
54+
}
55+
56+
if ($this->listening) {
57+
$this->loop->removeWriteStream($this->socket);
58+
$this->listening = false;
59+
}
60+
61+
$this->socket = false;
62+
$this->outgoing = array();
63+
}
4564
}

Datagram/Socket.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function close()
7878
{
7979
$this->emit('close', array($this));
8080
$this->pause();
81+
$this->buffer->close();
8182
$this->removeAllListeners();
8283

8384
fclose($this->socket);

0 commit comments

Comments
 (0)