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