Skip to content

Commit

Permalink
Handle pipe closing
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Sep 12, 2024
1 parent d5baec0 commit ad5e6e2
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 165 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX")
)
set(EVENT_LOOP_DEFINE "ON_EVENT_WITH_RESULT")
set(USE_S2N ON)
list(APPEND PLATFORM_LIBS "socket")
endif()

if (BYO_CRYPTO)
Expand Down
4 changes: 4 additions & 0 deletions include/aws/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ struct aws_event_loop;
struct aws_io_handle_io_op_result {
size_t read_bytes;
size_t written_bytes;
/** Error codes representing generic errors happening on I/O handles. */
int error_code;
/** Error codes specific to reading operations. */
int read_error_code;
/** Error codes specific to writing operations. */
int write_error_code;
};

Expand Down
13 changes: 13 additions & 0 deletions source/posix/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <aws/io/pipe.h>

#include <aws/io/event_loop.h>
#include <aws/common/logging.h>

#ifdef __GLIBC__
# define __USE_GNU
Expand Down Expand Up @@ -290,6 +291,16 @@ int aws_pipe_read(struct aws_pipe_read_end *read_end, struct aws_byte_buf *dst_b
}
return s_raise_posix_error(errno_value);
}
#if AWS_USE_ON_EVENT_WITH_RESULT
else if (read_val == 0) {
if (read_impl->handle.update_io_result) {
struct aws_io_handle_io_op_result io_op_result;
memset(&io_op_result, 0, sizeof(struct aws_io_handle_io_op_result));
io_op_result.error_code = AWS_IO_SOCKET_CLOSED;
read_impl->handle.update_io_result(read_impl->event_loop, &read_impl->handle, &io_op_result);
}
}
#endif

/* Success */
dst_buffer->len += read_val;
Expand All @@ -310,6 +321,8 @@ static void s_read_end_on_event(
(void)event_loop;
(void)handle;

AWS_LOGF_TRACE(12, "=== s_read_end_on_event is called");

/* Note that it should be impossible for this to run after read-end has been unsubscribed or cleaned up */
struct aws_pipe_read_end *read_end = user_data;
struct read_end_impl *read_impl = read_end->impl_data;
Expand Down
Loading

0 comments on commit ad5e6e2

Please sign in to comment.