@@ -1502,6 +1502,10 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp to) {
1502
1502
state = state -> _next ;
1503
1503
}
1504
1504
}
1505
+ /* Close the stream if requested and no more listeners are left */
1506
+ if ((stream -> flags & JANET_STREAM_TOCLOSE ) && !stream -> state ) {
1507
+ janet_stream_close (stream );
1508
+ }
1505
1509
}
1506
1510
}
1507
1511
}
@@ -1656,6 +1660,10 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
1656
1660
janet_unlisten (state , 0 );
1657
1661
state = next_state ;
1658
1662
}
1663
+ /* Close the stream if requested and no more listeners are left */
1664
+ if ((stream -> flags & JANET_STREAM_TOCLOSE ) && !stream -> state ) {
1665
+ janet_stream_close (stream );
1666
+ }
1659
1667
}
1660
1668
}
1661
1669
}
@@ -1854,6 +1862,10 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
1854
1862
1855
1863
state = next_state ;
1856
1864
}
1865
+ /* Close the stream if requested and no more listeners are left */
1866
+ if ((stream -> flags & JANET_STREAM_TOCLOSE ) && !stream -> state ) {
1867
+ janet_stream_close (stream );
1868
+ }
1857
1869
}
1858
1870
}
1859
1871
}
@@ -1970,6 +1982,11 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
1970
1982
status3 == JANET_ASYNC_STATUS_DONE ||
1971
1983
status4 == JANET_ASYNC_STATUS_DONE )
1972
1984
janet_unlisten (state , 0 );
1985
+ /* Close the stream if requested and no more listeners are left */
1986
+ JanetStream * stream = state -> stream ;
1987
+ if ((stream -> flags & JANET_STREAM_TOCLOSE ) && !stream -> state ) {
1988
+ janet_stream_close (stream );
1989
+ }
1973
1990
}
1974
1991
}
1975
1992
@@ -2495,11 +2512,11 @@ static JanetAsyncStatus handle_connect(JanetListenerState *s) {
2495
2512
if (res == 0 ) {
2496
2513
janet_schedule (s -> fiber , janet_wrap_abstract (s -> stream ));
2497
2514
} else {
2498
- // TODO help needed. janet_stream_close( s->stream) ;
2515
+ s -> stream -> flags |= JANET_STREAM_TOCLOSE ;
2499
2516
janet_cancel (s -> fiber , janet_cstringv (strerror (res )));
2500
2517
}
2501
2518
} else {
2502
- // TODO help needed. janet_stream_close( s->stream) ;
2519
+ s -> stream -> flags |= JANET_STREAM_TOCLOSE ;
2503
2520
janet_cancel (s -> fiber , janet_ev_lasterr ());
2504
2521
}
2505
2522
return JANET_ASYNC_STATUS_DONE ;
0 commit comments