|
3 | 3 |
|
4 | 4 | #pragma once |
5 | 5 |
|
6 | | -#include <asio.hpp> |
7 | 6 | #include <atomic> |
8 | 7 | #include <chrono> |
9 | 8 | #include <expected> |
|
18 | 17 | #include <unordered_map> |
19 | 18 | #include <vector> |
20 | 19 |
|
| 20 | +#include "glaze/ext/glaze_asio.hpp" |
21 | 21 | #include "glaze/net/http_router.hpp" |
22 | 22 | #include "glaze/util/key_transformers.hpp" |
23 | 23 |
|
@@ -240,7 +240,7 @@ namespace glz |
240 | 240 | bool expected = false; |
241 | 241 | if (should_stop.compare_exchange_strong(expected, true)) { |
242 | 242 | if (socket && socket->is_open()) { |
243 | | - std::error_code ec; |
| 243 | + asio::error_code ec; |
244 | 244 | // This cancels pending async operations on the socket, triggering their handlers |
245 | 245 | // with asio::error::operation_aborted. |
246 | 246 | socket->cancel(ec); |
@@ -813,7 +813,7 @@ namespace glz |
813 | 813 | asio::async_read_until( |
814 | 814 | *connection->socket, *connection->buffer, "\r\n", |
815 | 815 | [this, connection, on_data = std::move(on_data), on_error = std::move(on_error), |
816 | | - on_disconnect = std::move(on_disconnect)](std::error_code ec, std::size_t bytes_transferred) mutable { |
| 816 | + on_disconnect = std::move(on_disconnect)](asio::error_code ec, std::size_t bytes_transferred) mutable { |
817 | 817 | if (ec || connection->should_stop) { |
818 | 818 | if (ec != asio::error::eof && ec != asio::error::operation_aborted && !connection->should_stop) |
819 | 819 | on_error(ec); |
@@ -881,7 +881,7 @@ namespace glz |
881 | 881 | *connection->socket, *connection->buffer, |
882 | 882 | asio::transfer_exactly(total_to_read - connection->buffer->size()), |
883 | 883 | [this, connection, chunk_size, on_data = std::move(on_data), on_error = std::move(on_error), |
884 | | - on_disconnect = std::move(on_disconnect)](std::error_code ec, std::size_t) mutable { |
| 884 | + on_disconnect = std::move(on_disconnect)](asio::error_code ec, std::size_t) mutable { |
885 | 885 | if (ec || connection->should_stop) { |
886 | 886 | if (ec != asio::error::eof && ec != asio::error::operation_aborted && !connection->should_stop) |
887 | 887 | on_error(ec); |
@@ -931,7 +931,7 @@ namespace glz |
931 | 931 | // Use async_read with transfer_at_least(1) - may read more data for efficiency |
932 | 932 | asio::async_read( |
933 | 933 | *connection->socket, *connection->buffer, asio::transfer_at_least(1), |
934 | | - [this, connection, on_data, on_error, on_disconnect](std::error_code ec, |
| 934 | + [this, connection, on_data, on_error, on_disconnect](asio::error_code ec, |
935 | 935 | std::size_t /*bytes_transferred*/) { |
936 | 936 | if (ec || connection->should_stop) { |
937 | 937 | if (ec != asio::error::eof && ec != asio::error::operation_aborted && !connection->should_stop) { |
@@ -966,7 +966,7 @@ namespace glz |
966 | 966 | constexpr size_t read_size = 8192; |
967 | 967 | connection->socket->async_read_some( |
968 | 968 | connection->buffer->prepare(read_size), |
969 | | - [this, connection, on_data, on_error, on_disconnect](std::error_code ec, std::size_t bytes_transferred) { |
| 969 | + [this, connection, on_data, on_error, on_disconnect](asio::error_code ec, std::size_t bytes_transferred) { |
970 | 970 | if (ec || connection->should_stop) { |
971 | 971 | if (ec != asio::error::eof && ec != asio::error::operation_aborted && !connection->should_stop) { |
972 | 972 | on_error(ec); |
@@ -1033,11 +1033,11 @@ namespace glz |
1033 | 1033 |
|
1034 | 1034 | // Read response headers synchronously |
1035 | 1035 | asio::streambuf response_buffer; |
1036 | | - std::error_code ec; |
| 1036 | + asio::error_code ec; |
1037 | 1037 | size_t header_bytes = asio::read_until(*socket, response_buffer, "\r\n\r\n", ec); |
1038 | 1038 | if (ec) { |
1039 | 1039 | socket->close(); |
1040 | | - return std::unexpected(ec); |
| 1040 | + return std::unexpected<std::error_code>(ec); |
1041 | 1041 | } |
1042 | 1042 |
|
1043 | 1043 | // Create a zero-copy view of the header data |
@@ -1096,7 +1096,7 @@ namespace glz |
1096 | 1096 | size_t body_in_buffer = response_buffer.size(); |
1097 | 1097 | if (content_length > body_in_buffer) { |
1098 | 1098 | size_t remaining_to_read = content_length - body_in_buffer; |
1099 | | - std::error_code read_ec; |
| 1099 | + asio::error_code read_ec; |
1100 | 1100 | asio::read(*socket, response_buffer, asio::transfer_exactly(remaining_to_read), read_ec); |
1101 | 1101 | if (read_ec) { |
1102 | 1102 | socket->close(); // Don't reuse a failed connection |
@@ -1304,7 +1304,7 @@ namespace glz |
1304 | 1304 | *socket, *buffer, asio::transfer_exactly(remaining_to_read), |
1305 | 1305 | [this, socket, buffer, url, status_code = parsed_status->status_code, |
1306 | 1306 | response_headers = std::move(response_headers), |
1307 | | - handler = std::forward<CompletionHandler>(handler)](std::error_code ec, std::size_t) mutable { |
| 1307 | + handler = std::forward<CompletionHandler>(handler)](asio::error_code ec, std::size_t) mutable { |
1308 | 1308 | // EOF is expected if the server closes the connection. |
1309 | 1309 | if (ec && ec != asio::error::eof) { |
1310 | 1310 | handler(std::unexpected(ec)); |
|
0 commit comments