File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Datagram ;
4
4
5
+ use Evenement \EventEmitter ;
5
6
use React \EventLoop \LoopInterface ;
6
7
use \Exception ;
7
8
8
- class Buffer
9
+ class Buffer extends EventEmitter
9
10
{
10
11
private $ loop ;
11
12
private $ socket ;
@@ -46,7 +47,7 @@ public function handleWrite()
46
47
47
48
if ($ ret < 0 ) {
48
49
$ error = error_get_last ();
49
- throw new Exception ('Unable to send packet: ' . $ error ['message ' ]);
50
+ $ this -> emit ( ' error ' , array ( new Exception ('Unable to send packet: ' . $ error ['message ' ])) );
50
51
}
51
52
52
53
if (!$ this ->outgoing ) {
@@ -61,12 +62,15 @@ public function close()
61
62
return false ;
62
63
}
63
64
65
+ $ this ->emit ('close ' , array ($ this ));
66
+
64
67
if ($ this ->listening ) {
65
68
$ this ->loop ->removeWriteStream ($ this ->socket );
66
69
$ this ->listening = false ;
67
70
}
68
71
69
72
$ this ->socket = false ;
70
73
$ this ->outgoing = array ();
74
+ $ this ->removeAllListeners ();
71
75
}
72
76
}
Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ public function __construct(LoopInterface $loop, $socket)
20
20
$ this ->socket = $ socket ;
21
21
22
22
$ this ->buffer = new Buffer ($ loop , $ socket );
23
+ $ that = $ this ;
24
+ $ this ->buffer ->on ('error ' , function ($ error ) use ($ that ) {
25
+ $ that ->emit ('error ' , array ($ error , $ that ));
26
+ });
27
+ $ this ->buffer ->on ('close ' , array ($ this , 'close ' ));
23
28
24
29
$ this ->resume ();
25
30
}
You can’t perform that action at this time.
0 commit comments