Skip to content

Commit c2bccf0

Browse files
committed
Retrieve address from socket instead of passing it
1 parent 2fa74a2 commit c2bccf0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Datagram/Socket.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@ class Socket extends EventEmitter
1111
{
1212
protected $loop;
1313
protected $socket;
14-
protected $address;
1514

1615
public $bufferSize = 65536;
1716

18-
public function __construct(LoopInterface $loop, $socket, $address)
17+
public function __construct(LoopInterface $loop, $socket)
1918
{
2019
$this->loop = $loop;
2120
$this->socket = $socket;
22-
$this->address = $address;
2321

2422
$this->resume();
2523
}
2624

2725
public function getAddress()
2826
{
29-
return $this->address;
27+
return stream_socket_get_name($this->socket, false);
3028
}
3129

3230
public function getPort()
3331
{
34-
return (int)substr($this->address, strrpos($this->address, ':') + 1);
32+
$address = $this->getAddress();
33+
return (int)substr($address, strrpos($address, ':') + 1);
3534
}
3635

3736
public function getHost()
3837
{
39-
return trim(substr($this->address, 0, strrpos($this->address, ':')), '[]');
38+
$address = $this->getAddress();
39+
return trim(substr($address, 0, strrpos($address, ':')), '[]');
4040
}
4141

4242
public function send($data, $target = null)
@@ -101,6 +101,6 @@ private function sanitizeAddress($address)
101101

102102
public function __toString()
103103
{
104-
return $this->address . ' (' . $this->socket . ')';
104+
return $this->getAddress() . ' (' . $this->socket . ')';
105105
}
106106
}

0 commit comments

Comments
 (0)