Skip to content

Commit b60f6f0

Browse files
committed
Pass along $this Socket in message events
1 parent 6379a0d commit b60f6f0

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Datagram/Socket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function onReceive($message)
7373
return;
7474
}
7575

76-
$this->emit('message', array($data, $this->sanitizeAddress($peer)));
76+
$this->emit('message', array($data, $this->sanitizeAddress($peer), $this));
7777
}
7878

7979
public function close()

Datagram/SocketInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Evenement\EventEmitterInterface;
66

77
/**
8-
* @event message($data, $remoteAddress)
9-
* @event error($exception)
8+
* @event message($data, $remoteAddress, $thisSocket)
9+
* @event error($exception, $thisSocket)
1010
*/
1111
interface SocketInterface extends EventEmitterInterface
1212
{

example/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
$factory = new Datagram\Factory($loop);
88

99
$factory->createServer(1234)->then(function (Datagram\Socket $server) {
10-
$server->on('message', function($message, $address) use ($server) {
10+
$server->on('message', function($message, $address, $server) {
1111
$server->send('hello ' . $address . '! echo: ' . $message, $address);
1212

1313
echo 'client ' . $address . ': ' . $message . PHP_EOL;

0 commit comments

Comments
 (0)