1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-16 02:09:56 +00:00

net/ev: Cleaned up unused NetStateConnect, fixed janet_async_end() ev refcount

This commit is contained in:
Ico Doornekamp 2023-11-10 20:34:17 +01:00
parent a3228f4997
commit 9b640c8e9c
2 changed files with 5 additions and 12 deletions

View File

@ -258,12 +258,12 @@ void janet_async_end(JanetFiber *fiber) {
fiber->ev_callback(fiber, JANET_ASYNC_EVENT_DEINIT); fiber->ev_callback(fiber, JANET_ASYNC_EVENT_DEINIT);
janet_gcunroot(janet_wrap_abstract(fiber->ev_stream)); janet_gcunroot(janet_wrap_abstract(fiber->ev_stream));
fiber->ev_callback = NULL; fiber->ev_callback = NULL;
if (fiber->ev_state) { if (!(fiber->flags & JANET_FIBER_EV_FLAG_IN_FLIGHT)) {
if (!(fiber->flags & JANET_FIBER_EV_FLAG_IN_FLIGHT)) { if (fiber->ev_state) {
janet_free(fiber->ev_state); janet_free(fiber->ev_state);
janet_ev_dec_refcount(); fiber->ev_state = NULL;
} }
fiber->ev_state = NULL; janet_ev_dec_refcount();
} }
} }
} }

View File

@ -122,13 +122,9 @@ static void janet_net_socknoblock(JSock s) {
/* State machine for async connect */ /* State machine for async connect */
typedef struct {
int did_connect;
} NetStateConnect;
void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) { void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) {
JanetStream *stream = fiber->ev_stream; JanetStream *stream = fiber->ev_stream;
NetStateConnect *state = (NetStateConnect *)fiber->ev_state;
switch (event) { switch (event) {
default: default:
break; break;
@ -155,7 +151,6 @@ void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) {
#endif #endif
if (r == 0) { if (r == 0) {
if (res == 0) { if (res == 0) {
state->did_connect = 1;
janet_schedule(fiber, janet_wrap_abstract(stream)); janet_schedule(fiber, janet_wrap_abstract(stream));
} else { } else {
janet_cancel(fiber, janet_cstringv(strerror(res))); janet_cancel(fiber, janet_cstringv(strerror(res)));
@ -169,9 +164,7 @@ void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) {
} }
static JANET_NO_RETURN void net_sched_connect(JanetStream *stream) { static JANET_NO_RETURN void net_sched_connect(JanetStream *stream) {
NetStateConnect *state = janet_malloc(sizeof(NetStateConnect)); janet_async_start(stream, JANET_ASYNC_LISTEN_WRITE, net_callback_connect, NULL);
state->did_connect = 0;
janet_async_start(stream, JANET_ASYNC_LISTEN_WRITE, net_callback_connect, state);
} }
/* State machine for accepting connections. */ /* State machine for accepting connections. */