Skip to content

Commit dda4743

Browse files
committed
Merge v0.4.1 bugfix release
2 parents 002021b + 4888ddd commit dda4743

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ This file is a manually maintained list of changes for each release. Feel free
44
to add your changes here when sending pull requests. Also send corrections if
55
you spot any mistakes.
66

7+
## 0.4.1 (2014-06-13)
8+
9+
* Fix: Uncaught Exception while processing ICMP rejection datagrams
10+
([#12](https://github.com/clue/datagram/pull/12))
11+
712
## 0.4.0 (2014-03-03)
813

914
* BC break: Unified socket addresses (string URIs instead of host+port)

src/Socket.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use React\EventLoop\LoopInterface;
66
use Evenement\EventEmitter;
7+
use Exception;
78

89
class Socket extends EventEmitter implements SocketInterface
910
{
@@ -124,7 +125,7 @@ protected function handleReceive(&$peerAddress)
124125
// due to the nature of UDP, there's no way to tell which one exactly
125126
// $peer is not filled either
126127

127-
throw new \Exception('Invalid message');
128+
throw new Exception('Invalid message');
128129
}
129130

130131
$peerAddress = $this->sanitizeAddress($peerAddress);

tests/SocketTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,32 @@ public function testClientSendHugeWillFail()
8787
$this->loop->run();
8888
}
8989

90+
public function testClientSendNoServerWillFail()
91+
{
92+
$promise = $this->factory->createClient('127.0.0.1:1234');
93+
$client = $this->getValueFromResolvedPromise($promise);
94+
95+
// send a message to a socket that is not actually listening
96+
// expect the remote end to reject this by sending an ICMP message
97+
// which we will receive as an error message. This depends on the
98+
// host to actually reject UDP datagrams, which not all systems do.
99+
$client->send('hello');
100+
$client->on('error', $this->expectCallableOnce());
101+
102+
$loop = $this->loop;
103+
$client->on('error', function () use ($loop) {
104+
$loop->stop();
105+
});
106+
107+
$that = $this;
108+
$this->loop->addTimer(1.0, function () use ($that, $loop) {
109+
$loop->stop();
110+
$that->markTestSkipped('UDP packet was not rejected after 0.5s, ignoring test');
111+
});
112+
113+
$this->loop->run();
114+
}
115+
90116
public function testCreatePair()
91117
{
92118
$promise = $this->factory->createServer('127.0.0.1:0');

0 commit comments

Comments
 (0)