Skip to content

Commit f52cb7a

Browse files
committed
added JANET_STREAM_CLOSING to indicate the stream should be closed at the end of the event loop handling
1 parent 8d78fb1 commit f52cb7a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/core/ev.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,9 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp to) {
15021502
state = state->_next;
15031503
}
15041504
}
1505+
if(stream->flags |= JANET_STREAM_CLOSING) {
1506+
janet_stream_close(stream);
1507+
}
15051508
}
15061509
}
15071510
}
@@ -1656,6 +1659,9 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
16561659
janet_unlisten(state, 0);
16571660
state = next_state;
16581661
}
1662+
if(stream->flags |= JANET_STREAM_CLOSING) {
1663+
janet_stream_close(stream);
1664+
}
16591665
}
16601666
}
16611667
}
@@ -1854,6 +1860,9 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
18541860

18551861
state = next_state;
18561862
}
1863+
if(stream->flags |= JANET_STREAM_CLOSING) {
1864+
janet_stream_close(stream);
1865+
}
18571866
}
18581867
}
18591868
}
@@ -1970,6 +1979,9 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
19701979
status3 == JANET_ASYNC_STATUS_DONE ||
19711980
status4 == JANET_ASYNC_STATUS_DONE)
19721981
janet_unlisten(state, 0);
1982+
if(state->stream->flags |= JANET_STREAM_CLOSING) {
1983+
janet_stream_close(state->stream);
1984+
}
19731985
}
19741986
}
19751987

@@ -2495,11 +2507,11 @@ static JanetAsyncStatus handle_connect(JanetListenerState *s) {
24952507
if (res == 0) {
24962508
janet_schedule(s->fiber, janet_wrap_abstract(s->stream));
24972509
} else {
2498-
// TODO help needed. janet_stream_close(s->stream);
2510+
s->stream->flags |= JANET_STREAM_CLOSING;
24992511
janet_cancel(s->fiber, janet_cstringv(strerror(res)));
25002512
}
25012513
} else {
2502-
// TODO help needed. janet_stream_close(s->stream);
2514+
s->stream->flags |= JANET_STREAM_CLOSING;
25032515
janet_cancel(s->fiber, janet_ev_lasterr());
25042516
}
25052517
return JANET_ASYNC_STATUS_DONE;

src/include/janet.h

+1
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ typedef void *JanetAbstract;
564564
#define JANET_STREAM_CLOSED 0x1
565565
#define JANET_STREAM_SOCKET 0x2
566566
#define JANET_STREAM_IOCP 0x4
567+
#define JANET_STREAM_CLOSING 0x8
567568
#define JANET_STREAM_READABLE 0x200
568569
#define JANET_STREAM_WRITABLE 0x400
569570
#define JANET_STREAM_ACCEPTABLE 0x800

0 commit comments

Comments
 (0)