Skip to content

Commit 60c5c4e

Browse files
committed
Properly close() Socket
1 parent ec9721b commit 60c5c4e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Datagram/Socket.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public function __construct(LoopInterface $loop, $socket)
2626

2727
public function getAddress()
2828
{
29-
return stream_socket_get_name($this->socket, false);
29+
if ($this->socket !== false) {
30+
return stream_socket_get_name($this->socket, false);
31+
}
3032
}
3133

3234
public function getPort()
@@ -54,7 +56,9 @@ public function pause()
5456

5557
public function resume()
5658
{
57-
$this->loop->addReadStream($this->socket, array($this, 'onReceive'));
59+
if ($this->socket !== false) {
60+
$this->loop->addReadStream($this->socket, array($this, 'onReceive'));
61+
}
5862
}
5963

6064
public function onReceive($message)
@@ -76,13 +80,18 @@ public function onReceive($message)
7680

7781
public function close()
7882
{
83+
if ($this->socket === false) {
84+
return;
85+
}
86+
7987
$this->emit('close', array($this));
8088
$this->pause();
81-
$this->buffer->close();
82-
$this->removeAllListeners();
8389

84-
fclose($this->socket);
8590
$this->socket = false;
91+
$this->buffer->close();
92+
fclose($this->socket);
93+
94+
$this->removeAllListeners();
8695
}
8796

8897
private function sanitizeAddress($address)

0 commit comments

Comments
 (0)