File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use React \EventLoop \LoopInterface ;
6
6
use Evenement \EventEmitter ;
7
+ use Exception ;
7
8
8
9
class Socket extends EventEmitter implements SocketInterface
9
10
{
@@ -124,7 +125,7 @@ protected function handleReceive(&$peerAddress)
124
125
// due to the nature of UDP, there's no way to tell which one exactly
125
126
// $peer is not filled either
126
127
127
- throw new \ Exception ('Invalid message ' );
128
+ throw new Exception ('Invalid message ' );
128
129
}
129
130
130
131
$ peerAddress = $ this ->sanitizeAddress ($ peerAddress );
Original file line number Diff line number Diff line change @@ -87,6 +87,32 @@ public function testClientSendHugeWillFail()
87
87
$ this ->loop ->run ();
88
88
}
89
89
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
+
90
116
public function testCreatePair ()
91
117
{
92
118
$ promise = $ this ->factory ->createServer ('127.0.0.1:0 ' );
You can’t perform that action at this time.
0 commit comments