Skip to content

Commit cc338be

Browse files
committed
Implement cancelling listening on a socket.
1 parent cdf5c71 commit cc338be

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/io/asyncsocket.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,12 @@ static void listen_setup(MVMThreadContext *tc, uv_loop_t *loop, MVMObject *async
648648
uv_listen((uv_stream_t *)li->socket, 128, on_connection);
649649
}
650650

651+
/* Stops listening. */
652+
static void listen_cancel(MVMThreadContext *tc, uv_loop_t *loop, MVMObject *async_task, void *data) {
653+
ListenInfo *li = (ListenInfo *)data;
654+
uv_close((uv_handle_t *)li->socket, NULL);
655+
}
656+
651657
/* Frees info for a listen task. */
652658
static void listen_gc_free(MVMThreadContext *tc, MVMObject *t, void *data) {
653659
if (data) {
@@ -661,7 +667,7 @@ static void listen_gc_free(MVMThreadContext *tc, MVMObject *t, void *data) {
661667
/* Operations table for async listen task. */
662668
static const MVMAsyncTaskOps listen_op_table = {
663669
listen_setup,
664-
NULL,
670+
listen_cancel,
665671
NULL,
666672
listen_gc_free
667673
};

0 commit comments

Comments
 (0)