mirror of
https://github.com/janet-lang/janet
synced 2024-12-23 15:00:27 +00:00
Merge pull request #1325 from zevv/zevv-connect-cleanup
net/ev: Cleaned up unused NetStateConnect, fixed janet_async_end() ev refcount
This commit is contained in:
commit
f459e32ada
@ -258,12 +258,12 @@ void janet_async_end(JanetFiber *fiber) {
|
||||
fiber->ev_callback(fiber, JANET_ASYNC_EVENT_DEINIT);
|
||||
janet_gcunroot(janet_wrap_abstract(fiber->ev_stream));
|
||||
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_ev_dec_refcount();
|
||||
fiber->ev_state = NULL;
|
||||
}
|
||||
fiber->ev_state = NULL;
|
||||
janet_ev_dec_refcount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,13 +122,9 @@ static void janet_net_socknoblock(JSock s) {
|
||||
|
||||
/* State machine for async connect */
|
||||
|
||||
typedef struct {
|
||||
int did_connect;
|
||||
} NetStateConnect;
|
||||
|
||||
void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) {
|
||||
JanetStream *stream = fiber->ev_stream;
|
||||
NetStateConnect *state = (NetStateConnect *)fiber->ev_state;
|
||||
switch (event) {
|
||||
default:
|
||||
break;
|
||||
@ -155,7 +151,6 @@ void net_callback_connect(JanetFiber *fiber, JanetAsyncEvent event) {
|
||||
#endif
|
||||
if (r == 0) {
|
||||
if (res == 0) {
|
||||
state->did_connect = 1;
|
||||
janet_schedule(fiber, janet_wrap_abstract(stream));
|
||||
} else {
|
||||
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) {
|
||||
NetStateConnect *state = janet_malloc(sizeof(NetStateConnect));
|
||||
state->did_connect = 0;
|
||||
janet_async_start(stream, JANET_ASYNC_LISTEN_WRITE, net_callback_connect, state);
|
||||
janet_async_start(stream, JANET_ASYNC_LISTEN_WRITE, net_callback_connect, NULL);
|
||||
}
|
||||
|
||||
/* State machine for accepting connections. */
|
||||
|
Loading…
Reference in New Issue
Block a user