@@ -184,6 +184,77 @@ public function testRemoveStreamForWriteOnly()
184184 $ this ->tickLoop ($ this ->loop );
185185 }
186186
187+ public function testRemoveReadAndWriteStreamFromLoopOnceResourceClosesEndsLoop ()
188+ {
189+ list ($ stream , $ other ) = $ this ->createSocketPair ();
190+ stream_set_blocking ($ stream , false );
191+ stream_set_blocking ($ other , false );
192+
193+ // dummy writable handler
194+ $ this ->loop ->addWriteStream ($ stream , function () { });
195+
196+ // remove stream when the stream is readable (closes)
197+ $ this ->loop ->addReadStream ($ stream , function ($ stream ) {
198+ $ this ->loop ->removeReadStream ($ stream );
199+ $ this ->loop ->removeWriteStream ($ stream );
200+ fclose ($ stream );
201+ });
202+
203+ // close other side
204+ fclose ($ other );
205+
206+ $ this ->assertRunFasterThan ($ this ->tickTimeout );
207+ }
208+
209+ public function testRemoveReadAndWriteStreamFromLoopOnceResourceClosesOnEndOfFileEndsLoop ()
210+ {
211+ list ($ stream , $ other ) = $ this ->createSocketPair ();
212+ stream_set_blocking ($ stream , false );
213+ stream_set_blocking ($ other , false );
214+
215+ // dummy writable handler
216+ $ this ->loop ->addWriteStream ($ stream , function () { });
217+
218+ // remove stream when the stream is readable (closes)
219+ $ this ->loop ->addReadStream ($ stream , function ($ stream ) {
220+ $ data = fread ($ stream , 1024 );
221+ if ($ data !== '' ) {
222+ return ;
223+ }
224+
225+ $ this ->loop ->removeReadStream ($ stream );
226+ $ this ->loop ->removeWriteStream ($ stream );
227+ fclose ($ stream );
228+ });
229+
230+ // send data and close stream
231+ fwrite ($ other , str_repeat ('. ' , 60000 ));
232+ $ this ->loop ->addTimer (0.01 , function () use ($ other ) {
233+ fclose ($ other );
234+ });
235+
236+ $ this ->assertRunFasterThan (0.1 );
237+ }
238+
239+ public function testRemoveReadAndWriteStreamFromLoopWithClosingResourceEndsLoop ()
240+ {
241+ // get only one part of the pair to ensure the other side will close immediately
242+ list ($ stream ) = $ this ->createSocketPair ();
243+ stream_set_blocking ($ stream , false );
244+
245+ // dummy writable handler
246+ $ this ->loop ->addWriteStream ($ stream , function () { });
247+
248+ // remove stream when the stream is readable (closes)
249+ $ this ->loop ->addReadStream ($ stream , function ($ stream ) {
250+ $ this ->loop ->removeReadStream ($ stream );
251+ $ this ->loop ->removeWriteStream ($ stream );
252+ fclose ($ stream );
253+ });
254+
255+ $ this ->assertRunFasterThan ($ this ->tickTimeout );
256+ }
257+
187258 public function testRemoveInvalid ()
188259 {
189260 list ($ stream ) = $ this ->createSocketPair ();
0 commit comments