Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
06d58b8
setup ci test for dispatch queue
xiazhvera Feb 10, 2025
3479012
kick ci
xiazhvera Feb 11, 2025
e86a7cb
WIP: test async listen
xiazhvera Feb 12, 2025
bd7fb0f
use async listen for apple
xiazhvera Feb 12, 2025
c4252cf
use platform default socket impl
xiazhvera Feb 12, 2025
8c97197
improve error handle
xiazhvera Feb 12, 2025
9123237
disable sanitizer
xiazhvera Feb 12, 2025
b6df45b
test with a http site
xiazhvera Feb 21, 2025
92cd411
add evil print all decoded data
xiazhvera Feb 21, 2025
60e7cdb
more prints for the error line
xiazhvera Feb 21, 2025
c486316
more prints
xiazhvera Feb 21, 2025
d7efa17
print more
xiazhvera Feb 21, 2025
233e258
more prints for set_line/state
xiazhvera Feb 24, 2025
aac4b01
prints
xiazhvera Feb 24, 2025
ba8a7e2
test on different macos os version
xiazhvera Feb 24, 2025
2db9954
revert test
xiazhvera Feb 24, 2025
75567b3
try h2 with plain
xiazhvera Feb 24, 2025
32e6e21
try non-tls test
xiazhvera Feb 24, 2025
31e5b07
revert unit test
xiazhvera Feb 24, 2025
7cdb573
use s3 plain test
xiazhvera Feb 25, 2025
7689c3b
revert unit test
xiazhvera Feb 25, 2025
891f500
test against static stspn
xiazhvera Feb 25, 2025
a26c527
test with a 200m file
xiazhvera Feb 25, 2025
71d071d
200m is too large, try 134m
xiazhvera Feb 25, 2025
0e4fac8
revert the test again
xiazhvera Feb 26, 2025
a2077ed
forgot to revert the tls option
xiazhvera Feb 26, 2025
4341fed
cleanup testing prints
xiazhvera Feb 26, 2025
42bf9bd
update ci runner
xiazhvera Feb 26, 2025
62cd703
kick ci
xiazhvera Feb 28, 2025
199ccc8
Merge branch 'nw_socket' of github.com:awslabs/aws-c-http into nw_soc…
xiazhvera Mar 5, 2025
5a7f7c5
remove aws_server_bootstrap_new_socket_listener_async
xiazhvera Mar 5, 2025
629c838
handle listener setup error
xiazhvera Mar 6, 2025
8fe08ac
clang-format
xiazhvera Mar 6, 2025
a41e7a1
Merge branch 'main' into nw_socket
xiazhvera Mar 12, 2025
85bd1c6
update to use future
xiazhvera Mar 17, 2025
70a9bae
Merge branch 'nw_socket' of github.com:awslabs/aws-c-http into nw_socket
xiazhvera Mar 17, 2025
91712b3
Merge branch 'main' into nw_socket
xiazhvera Mar 17, 2025
acf0f5c
kick ci for codebuild
xiazhvera Mar 17, 2025
2c2c491
code review update
xiazhvera Mar 17, 2025
d047ebe
clean up server socket
xiazhvera Mar 17, 2025
957e9f5
remove unnecessary validation
xiazhvera Mar 17, 2025
1594c97
remove mutex flag
xiazhvera Mar 17, 2025
4e59081
remove space
xiazhvera Mar 17, 2025
bee341b
Update source/connection.c
xiazhvera Mar 18, 2025
b46458e
Merge branch 'main' into nw_socket
xiazhvera Mar 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ jobs:
python .\aws-c-http\build\deps\aws-c-common\scripts\appverifier_ctest.py --build_directory .\aws-c-http\build\aws-c-http

macos:
runs-on: macos-14 # latest
runs-on: macos-14
strategy:
fail-fast: false
matrix:
eventloop: ["kqueue", "dispatch_queue"]
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -214,10 +218,10 @@ jobs:
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }}
./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }}

macos-x64:
runs-on: macos-14-large # latest
runs-on: macos-14-large
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -244,7 +248,11 @@ jobs:
python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --config Debug

localhost-test-macos:
runs-on: macos-14 # latest
runs-on: macos-14
strategy:
fail-fast: false
matrix:
eventloop: ["kqueue", "dispatch_queue"]
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -257,7 +265,7 @@ jobs:
python3 -m venv .venv
source .venv/bin/activate
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --config Debug
python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=${{ matrix.eventloop == 'dispatch_queue' && 'ON' || 'OFF' }} --config Debug

localhost-test-win:
runs-on: windows-2022 # latest
Expand Down
56 changes: 43 additions & 13 deletions source/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <aws/common/string.h>
#include <aws/http/request_response.h>
#include <aws/io/channel_bootstrap.h>
#include <aws/io/future.h>
#include <aws/io/logging.h>
#include <aws/io/socket.h>
#include <aws/io/socket_channel_handler.h>
Expand Down Expand Up @@ -58,6 +59,7 @@ struct aws_http_server {
aws_http_server_on_incoming_connection_fn *on_incoming_connection;
aws_http_server_on_destroy_fn *on_destroy_complete;
struct aws_socket *socket;
struct aws_future_void *setup_future;

/* Any thread may touch this data, but the lock must be held */
struct {
Expand Down Expand Up @@ -576,6 +578,7 @@ static void s_http_server_clean_up(struct aws_http_server *server) {
}
aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map);
aws_mutex_clean_up(&server->synced_data.lock);
aws_future_void_release(server->setup_future);
aws_mem_release(server->alloc, server);
}

Expand Down Expand Up @@ -621,6 +624,20 @@ static void s_server_bootstrap_on_server_listener_destroy(struct aws_server_boot
s_http_server_clean_up(server);
}

/* the server listener has finished setup. We released the socket if error_code is not 0. */
static void s_server_bootstrap_on_server_listener_setup(
struct aws_server_bootstrap *bootstrap,
int error_code,
void *user_data) {
(void)bootstrap;
struct aws_http_server *server = user_data;
if (error_code) {
aws_future_void_set_error(server->setup_future, error_code);
} else {
aws_future_void_set_result(server->setup_future);
}
}

struct aws_http_server *aws_http_server_new(const struct aws_http_server_options *options) {
aws_http_fatal_assert_library_initialized();

Expand Down Expand Up @@ -654,7 +671,7 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options
if (err) {
AWS_LOGF_ERROR(
AWS_LS_HTTP_SERVER, "static: Failed to initialize mutex, error %d (%s).", err, aws_error_name(err));
goto mutex_error;
goto server_error;
}
err = aws_hash_table_init(
&server->synced_data.channel_to_connection_map, server->alloc, 16, aws_hash_ptr, aws_ptr_eq, NULL, NULL);
Expand All @@ -664,14 +681,16 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options
"static: Cannot create server, error %d (%s).",
aws_last_error(),
aws_error_name(aws_last_error()));
goto hash_table_error;
goto server_error;
}
/* Protect against callbacks firing before server->socket is set */
s_server_lock_synced_data(server);
if (options->tls_options) {
server->is_using_tls = true;
}

server->setup_future = aws_future_void_new(options->allocator);

struct aws_server_socket_channel_bootstrap_options bootstrap_options = {
.enable_read_back_pressure = options->manual_window_management,
.tls_options = options->tls_options,
Expand All @@ -680,23 +699,38 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options
.incoming_callback = s_server_bootstrap_on_accept_channel_setup,
.shutdown_callback = s_server_bootstrap_on_accept_channel_shutdown,
.destroy_callback = s_server_bootstrap_on_server_listener_destroy,
.setup_callback = s_server_bootstrap_on_server_listener_setup,
.host_name = options->endpoint->address,
.port = options->endpoint->port,
.user_data = server,
};

server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options);
int listen_error = AWS_OP_SUCCESS;

/*
* WARNING & TODO!!!!
* aws_server_bootstrap_new_socket_listener has async callback, we would block here waiting for
* setup complete. aws-c-http library need to be updated with a proper async API.
*/
server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options);
// if server setup properly, waiting for setup callback
if (server->socket) {
aws_future_void_wait(server->setup_future, UINT64_MAX /*timeout*/);
listen_error = aws_future_void_get_error(server->setup_future);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this path, aws_raise_error() is never called, so the aws_http_server_new() is going to return NULL, but if the user calls aws_last_error() to find out why they'll get 0 or whatever stale old error was on the stack

} else {
listen_error = aws_last_error();
}
s_server_unlock_synced_data(server);

if (!server->socket) {
if (listen_error) {
AWS_LOGF_ERROR(
AWS_LS_HTTP_SERVER,
"static: Failed creating new socket listener, error %d (%s). Cannot create server.",
aws_last_error(),
aws_error_name(aws_last_error()));
listen_error,
aws_error_name(listen_error));

goto socket_error;
aws_raise_error(listen_error);
goto server_error;
}

AWS_LOGF_INFO(
Expand All @@ -708,12 +742,8 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options

return server;

socket_error:
aws_hash_table_clean_up(&server->synced_data.channel_to_connection_map);
hash_table_error:
aws_mutex_clean_up(&server->synced_data.lock);
mutex_error:
aws_mem_release(server->alloc, server);
server_error:
s_http_server_clean_up(server);
return NULL;
}

Expand Down