Skip to content

Commit

Permalink
TESTING: releasing the socket
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed Sep 3, 2024
1 parent f983987 commit 9c2657c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 2 additions & 5 deletions source/darwin/dispatch_queue_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions source/darwin/nw_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
Expand Down Expand Up @@ -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);
});
}

Expand Down
3 changes: 2 additions & 1 deletion source/windows/iocp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9c2657c

Please sign in to comment.