Skip to content

Commit

Permalink
fix ssl compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Jan 23, 2025
1 parent 04a05fe commit bb1564e
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions include/ylt/coro_io/coro_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ post(Func func,
return post(std::move(func), e->get_asio_executor());
}

namespace detail {

template <typename T>
void cancel(T &io_object) {
if constexpr (requires { io_object.cancel(); }) {
io_object.cancel();
}
else {
io_object.lowest_layer().cancel();
}
}
} // namespace detail

template <typename ret_type, typename IO_func, typename io_object>
inline async_simple::coro::Lazy<ret_type> async_io(IO_func io_func,
io_object &obj) noexcept {
Expand Down Expand Up @@ -226,7 +239,7 @@ inline async_simple::coro::Lazy<ret_type> async_io(IO_func io_func,
bool expected = false;
if (!ptr->compare_exchange_strong(
expected, true, std::memory_order_release)) {
obj.cancel();
detail::cancel(obj);
}
}
});
Expand All @@ -247,7 +260,7 @@ inline async_simple::coro::Lazy<ret_type> async_io(IO_func io_func,
bool expected = false;
if (!lock->compare_exchange_strong(expected, true,
std::memory_order_release)) {
obj.cancel();
detail::cancel(obj);
}
lock = nullptr;
}
Expand All @@ -257,7 +270,6 @@ inline async_simple::coro::Lazy<ret_type> async_io(IO_func io_func,
lock = nullptr;
// wait cancel finish to make sure io object's life-time
for (; weak_lock.lock();) {
std::cout << "SHIT" << std::endl;
co_await coro_io::post(
[]() {
},
Expand All @@ -281,7 +293,7 @@ template <typename Socket, typename AsioBuffer>
inline async_simple::coro::Lazy<std::pair<std::error_code, size_t>>
async_read_some(Socket &socket, AsioBuffer buffer) noexcept {
return async_io<std::pair<std::error_code, size_t>>(
[&,buffer](auto &&cb) {
[&, buffer](auto &&cb) {
socket.async_read_some(buffer, std::move(cb));
},
socket);
Expand All @@ -291,7 +303,7 @@ template <typename Socket, typename AsioBuffer>
inline async_simple::coro::Lazy<std::pair<std::error_code, size_t>>
async_read_at(uint64_t offset, Socket &socket, AsioBuffer buffer) noexcept {
return async_io<std::pair<std::error_code, size_t>>(
[&socket,buffer,offset](auto &&cb) {
[&socket, buffer, offset](auto &&cb) {
asio::async_read_at(socket, offset, buffer, std::move(cb));
},
socket);
Expand All @@ -301,7 +313,7 @@ template <typename Socket, typename AsioBuffer>
inline async_simple::coro::Lazy<std::pair<std::error_code, size_t>> async_read(
Socket &socket, AsioBuffer buffer) noexcept {
return async_io<std::pair<std::error_code, size_t>>(
[&socket,buffer](auto &&cb) {
[&socket, buffer](auto &&cb) {
asio::async_read(socket, buffer, std::move(cb));
},
socket);
Expand All @@ -311,7 +323,7 @@ template <typename Socket, typename AsioBuffer>
inline async_simple::coro::Lazy<std::pair<std::error_code, size_t>> async_read(
Socket &socket, AsioBuffer &buffer, size_t size_to_read) noexcept {
return async_io<std::pair<std::error_code, size_t>>(
[&,size_to_read](auto &&cb) {
[&, size_to_read](auto &&cb) {
asio::async_read(socket, buffer, asio::transfer_exactly(size_to_read),
std::move(cb));
},
Expand All @@ -333,7 +345,7 @@ template <typename Socket, typename AsioBuffer>
inline async_simple::coro::Lazy<std::pair<std::error_code, size_t>> async_write(
Socket &socket, AsioBuffer buffer) noexcept {
return async_io<std::pair<std::error_code, size_t>>(
[&,buffer](auto &&cb) {
[&, buffer](auto &&cb) {
asio::async_write(socket, buffer, std::move(cb));
},
socket);
Expand All @@ -343,7 +355,7 @@ template <typename Socket, typename AsioBuffer>
inline async_simple::coro::Lazy<std::pair<std::error_code, size_t>>
async_write_some(Socket &socket, AsioBuffer buffer) noexcept {
return async_io<std::pair<std::error_code, size_t>>(
[&,buffer](auto &&cb) {
[&, buffer](auto &&cb) {
socket.async_write_some(buffer, std::move(cb));
},
socket);
Expand All @@ -353,7 +365,7 @@ template <typename Socket, typename AsioBuffer>
inline async_simple::coro::Lazy<std::pair<std::error_code, size_t>>
async_write_at(uint64_t offset, Socket &socket, AsioBuffer buffer) noexcept {
return async_io<std::pair<std::error_code, size_t>>(
[&, offset,buffer](auto &&cb) {
[&, offset, buffer](auto &&cb) {
asio::async_write_at(socket, offset, buffer, std::move(cb));
},
socket);
Expand Down Expand Up @@ -404,7 +416,7 @@ inline async_simple::coro::Lazy<std::error_code> async_handshake(
[&, type](auto &&cb) {
ssl_stream->async_handshake(type, std::move(cb));
},
ssl_stream);
*ssl_stream);
}
#endif
class period_timer : public asio::steady_timer {
Expand Down

0 comments on commit bb1564e

Please sign in to comment.