Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:51

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // Copyright (c) Lewis Baker
0003 // Licenced under MIT license. See LICENSE.txt for details.
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #ifndef CPPCORO_NET_SOCKET_SEND_OPERATION_HPP_INCLUDED
0006 #define CPPCORO_NET_SOCKET_SEND_OPERATION_HPP_INCLUDED
0007 
0008 #include <cppcoro/config.hpp>
0009 #include <cppcoro/cancellation_token.hpp>
0010 
0011 #include <cstdint>
0012 
0013 #if CPPCORO_OS_WINNT
0014 # include <cppcoro/detail/win32.hpp>
0015 # include <cppcoro/detail/win32_overlapped_operation.hpp>
0016 
0017 namespace cppcoro::net
0018 {
0019     class socket;
0020 
0021     class socket_send_operation_impl
0022     {
0023     public:
0024 
0025         socket_send_operation_impl(
0026             socket& s,
0027             const void* buffer,
0028             std::size_t byteCount) noexcept
0029             : m_socket(s)
0030             , m_buffer(const_cast<void*>(buffer), byteCount)
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 
0036     private:
0037 
0038         socket& m_socket;
0039         cppcoro::detail::win32::wsabuf m_buffer;
0040 
0041     };
0042 
0043     class socket_send_operation
0044         : public cppcoro::detail::win32_overlapped_operation<socket_send_operation>
0045     {
0046     public:
0047 
0048         socket_send_operation(
0049             socket& s,
0050             const void* buffer,
0051             std::size_t byteCount) noexcept
0052             : m_impl(s, buffer, byteCount)
0053         {}
0054 
0055     private:
0056 
0057         friend class cppcoro::detail::win32_overlapped_operation<socket_send_operation>;
0058 
0059         bool try_start() noexcept { return m_impl.try_start(*this); }
0060 
0061         socket_send_operation_impl m_impl;
0062 
0063     };
0064 
0065     class socket_send_operation_cancellable
0066         : public cppcoro::detail::win32_overlapped_operation_cancellable<socket_send_operation_cancellable>
0067     {
0068     public:
0069 
0070         socket_send_operation_cancellable(
0071             socket& s,
0072             const void* buffer,
0073             std::size_t byteCount,
0074             cancellation_token&& ct) noexcept
0075             : cppcoro::detail::win32_overlapped_operation_cancellable<socket_send_operation_cancellable>(std::move(ct))
0076             , m_impl(s, buffer, byteCount)
0077         {}
0078 
0079     private:
0080 
0081         friend class cppcoro::detail::win32_overlapped_operation_cancellable<socket_send_operation_cancellable>;
0082 
0083         bool try_start() noexcept { return m_impl.try_start(*this); }
0084         void cancel() noexcept { return m_impl.cancel(*this); }
0085 
0086         socket_send_operation_impl m_impl;
0087 
0088     };
0089 
0090 }
0091 
0092 #endif // CPPCORO_OS_WINNT
0093 
0094 #endif