diff --git a/source/darwin/dispatch_queue_event_loop.c b/source/darwin/dispatch_queue_event_loop.c index d3b23de16..1f4c1ab12 100644 --- a/source/darwin/dispatch_queue_event_loop.c +++ b/source/darwin/dispatch_queue_event_loop.c @@ -198,7 +198,7 @@ struct aws_event_loop *aws_event_loop_new_dispatch_queue_with_options( dispatch_set_context(dispatch_loop->dispatch_queue, loop); // Definalizer will be called on dispatch queue ref drop to 0 dispatch_set_finalizer_f(dispatch_loop->dispatch_queue, &s_finalize); - + aws_thread_increment_unjoined_count(); return loop; @@ -464,10 +464,7 @@ static void s_schedule_task_future(struct aws_event_loop *event_loop, struct aws static void s_cancel_task(struct aws_event_loop *event_loop, struct aws_task *task) { AWS_LOGF_TRACE(AWS_LS_IO_EVENT_LOOP, "id=%p: cancelling task %p", (void *)event_loop, (void *)task); struct dispatch_loop *dispatch_loop = event_loop->impl_data; - - dispatch_async(dispatch_loop->dispatch_queue, ^{ - aws_task_scheduler_cancel_task(&dispatch_loop->scheduler, task); - }); + aws_task_scheduler_cancel_task(&dispatch_loop->scheduler, task); } static int s_connect_to_dispatch_queue(struct aws_event_loop *event_loop, struct aws_io_handle *handle) { diff --git a/source/darwin/nw_socket.c b/source/darwin/nw_socket.c index 1b0b02d42..94f99c011 100644 --- a/source/darwin/nw_socket.c +++ b/source/darwin/nw_socket.c @@ -825,7 +825,9 @@ static void s_schedule_next_read(struct aws_socket *socket) { struct aws_allocator *allocator = socket->allocator; struct aws_linked_list *list = &nw_socket->read_queue; - + // DEBUG: Try acquire socket when connection receive + aws_ref_count_acquire(&nw_socket->ref_count); + /* read and let me know when you've done it. */ nw_connection_receive( socket->io_handle.data.handle, @@ -836,6 +838,7 @@ static void s_schedule_next_read(struct aws_socket *socket) { AWS_LOGF_TRACE( AWS_LS_IO_SOCKET, "id=%p handle=%p: read cb invoked", (void *)socket, socket->io_handle.data.handle); + if (!error || nw_error_get_error_code(error) == 0) { if (data) { struct read_queue_node *node = aws_mem_calloc(allocator, 1, sizeof(struct read_queue_node)); @@ -870,7 +873,9 @@ static void s_schedule_next_read(struct aws_socket *socket) { // DEBUG WIP these may or may not be necessary. release on error seems okay but // release on context or data here appears to double release. // nw_release(context); - nw_release(error); + nw_release(error); + // DEBUG: Try release socket when connection receive + aws_ref_count_release(&nw_socket->ref_count); }); } diff --git a/source/windows/iocp/socket.c b/source/windows/iocp/socket.c index 0378a183e..9d2bff163 100644 --- a/source/windows/iocp/socket.c +++ b/source/windows/iocp/socket.c @@ -424,7 +424,8 @@ void aws_socket_clean_up(struct aws_socket *socket) { aws_mem_release(socket->allocator, socket_impl->read_io_data); } - aws_mem_release(socket->allocator, socket->impl); + // DEBUG: socket impl is released in the impl functions + //aws_mem_release(socket->allocator, socket->impl); AWS_ZERO_STRUCT(*socket); socket->io_handle.data.handle = INVALID_HANDLE_VALUE; }