Skip to content

Commit

Permalink
check if nw_socket is open before trying to cancel/close
Browse files Browse the repository at this point in the history
  • Loading branch information
sbSteveK committed Sep 24, 2024
1 parent bfd662e commit d4959a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/aws/io/private/pki_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#ifdef AWS_OS_APPLE
/* It's ok to include external headers because this is a PRIVATE header file */
# include <CoreFoundation/CFArray.h>
#include <CoreFoundation/CFArray.h>
#include <Security/Security.h>
struct aws_secitem_options;
#endif /* AWS_OS_APPLE */

struct aws_secitem_options;
struct aws_string;

AWS_EXTERN_C_BEGIN
Expand Down
7 changes: 4 additions & 3 deletions source/darwin/nw_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,11 +1016,13 @@ static int s_socket_close_fn(struct aws_socket *socket) {
if (nw_socket->is_listener) {
nw_listener_set_state_changed_handler(socket->io_handle.data.handle, NULL);
nw_listener_cancel(socket->io_handle.data.handle);

} else {
if (nw_socket->socket_open) {
nw_connection_cancel(socket->io_handle.data.handle);
}

/* Setting to NULL removes previously set handler from nw_connection_t */
nw_connection_set_state_changed_handler(socket->io_handle.data.handle, NULL);
nw_connection_cancel(socket->io_handle.data.handle);
}
nw_socket->socket_open = false;

Expand Down Expand Up @@ -1331,7 +1333,6 @@ static int s_socket_get_error_fn(struct aws_socket *socket) {

static bool s_socket_is_open_fn(struct aws_socket *socket) {
struct nw_socket *nw_socket = socket->impl;

if (!socket->io_handle.data.handle) {
return false;
}
Expand Down

0 comments on commit d4959a6

Please sign in to comment.