File indexing completed on 2025-03-13 09:06:32
0001
0002
0003
0004
0005 #ifndef CPPCORO_NET_SOCKET_CONNECT_OPERATION_HPP_INCLUDED
0006 #define CPPCORO_NET_SOCKET_CONNECT_OPERATION_HPP_INCLUDED
0007
0008 #include <cppcoro/config.hpp>
0009 #include <cppcoro/cancellation_token.hpp>
0010 #include <cppcoro/net/ip_endpoint.hpp>
0011
0012 #if CPPCORO_OS_WINNT
0013 # include <cppcoro/detail/win32.hpp>
0014 # include <cppcoro/detail/win32_overlapped_operation.hpp>
0015
0016 namespace cppcoro
0017 {
0018 namespace net
0019 {
0020 class socket;
0021
0022 class socket_connect_operation_impl
0023 {
0024 public:
0025
0026 socket_connect_operation_impl(
0027 socket& socket,
0028 const ip_endpoint& remoteEndPoint) noexcept
0029 : m_socket(socket)
0030 , m_remoteEndPoint(remoteEndPoint)
0031 {}
0032
0033 bool try_start(cppcoro::detail::win32_overlapped_operation_base& operation) noexcept;
0034 void cancel(cppcoro::detail::win32_overlapped_operation_base& operation) noexcept;
0035 void get_result(cppcoro::detail::win32_overlapped_operation_base& operation);
0036
0037 private:
0038
0039 socket& m_socket;
0040 ip_endpoint m_remoteEndPoint;
0041
0042 };
0043
0044 class socket_connect_operation
0045 : public cppcoro::detail::win32_overlapped_operation<socket_connect_operation>
0046 {
0047 public:
0048
0049 socket_connect_operation(
0050 socket& socket,
0051 const ip_endpoint& remoteEndPoint) noexcept
0052 : m_impl(socket, remoteEndPoint)
0053 {}
0054
0055 private:
0056
0057 friend class cppcoro::detail::win32_overlapped_operation<socket_connect_operation>;
0058
0059 bool try_start() noexcept { return m_impl.try_start(*this); }
0060 decltype(auto) get_result() { return m_impl.get_result(*this); }
0061
0062 socket_connect_operation_impl m_impl;
0063
0064 };
0065
0066 class socket_connect_operation_cancellable
0067 : public cppcoro::detail::win32_overlapped_operation_cancellable<socket_connect_operation_cancellable>
0068 {
0069 public:
0070
0071 socket_connect_operation_cancellable(
0072 socket& socket,
0073 const ip_endpoint& remoteEndPoint,
0074 cancellation_token&& ct) noexcept
0075 : cppcoro::detail::win32_overlapped_operation_cancellable<socket_connect_operation_cancellable>(std::move(ct))
0076 , m_impl(socket, remoteEndPoint)
0077 {}
0078
0079 private:
0080
0081 friend class cppcoro::detail::win32_overlapped_operation_cancellable<socket_connect_operation_cancellable>;
0082
0083 bool try_start() noexcept { return m_impl.try_start(*this); }
0084 void cancel() noexcept { m_impl.cancel(*this); }
0085 void get_result() { m_impl.get_result(*this); }
0086
0087 socket_connect_operation_impl m_impl;
0088
0089 };
0090 }
0091 }
0092
0093 #endif
0094
0095 #endif