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_ACCEPT_OPERATION_HPP_INCLUDED
0006 #define CPPCORO_NET_SOCKET_ACCEPT_OPERATION_HPP_INCLUDED
0007 
0008 #include <cppcoro/config.hpp>
0009 #include <cppcoro/cancellation_token.hpp>
0010 #include <cppcoro/cancellation_registration.hpp>
0011 
0012 #if CPPCORO_OS_WINNT
0013 # include <cppcoro/detail/win32.hpp>
0014 # include <cppcoro/detail/win32_overlapped_operation.hpp>
0015 
0016 # include <atomic>
0017 # include <optional>
0018 
0019 namespace cppcoro
0020 {
0021     namespace net
0022     {
0023         class socket;
0024 
0025         class socket_accept_operation_impl
0026         {
0027         public:
0028 
0029             socket_accept_operation_impl(
0030                 socket& listeningSocket,
0031                 socket& acceptingSocket) noexcept
0032                 : m_listeningSocket(listeningSocket)
0033                 , m_acceptingSocket(acceptingSocket)
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             void get_result(cppcoro::detail::win32_overlapped_operation_base& operation);
0039 
0040         private:
0041 
0042 #if CPPCORO_COMPILER_MSVC
0043 # pragma warning(push)
0044 # pragma warning(disable : 4324) // Structure padded due to alignment
0045 #endif
0046 
0047             socket& m_listeningSocket;
0048             socket& m_acceptingSocket;
0049             alignas(8) std::uint8_t m_addressBuffer[88];
0050 
0051 #if CPPCORO_COMPILER_MSVC
0052 # pragma warning(pop)
0053 #endif
0054 
0055         };
0056 
0057         class socket_accept_operation
0058             : public cppcoro::detail::win32_overlapped_operation<socket_accept_operation>
0059         {
0060         public:
0061 
0062             socket_accept_operation(
0063                 socket& listeningSocket,
0064                 socket& acceptingSocket) noexcept
0065                 : m_impl(listeningSocket, acceptingSocket)
0066             {}
0067 
0068         private:
0069 
0070             friend class cppcoro::detail::win32_overlapped_operation<socket_accept_operation>;
0071 
0072             bool try_start() noexcept { return m_impl.try_start(*this); }
0073             void get_result() { m_impl.get_result(*this); }
0074 
0075             socket_accept_operation_impl m_impl;
0076 
0077         };
0078 
0079         class socket_accept_operation_cancellable
0080             : public cppcoro::detail::win32_overlapped_operation_cancellable<socket_accept_operation_cancellable>
0081         {
0082         public:
0083 
0084             socket_accept_operation_cancellable(
0085                 socket& listeningSocket,
0086                 socket& acceptingSocket,
0087                 cancellation_token&& ct) noexcept
0088                 : cppcoro::detail::win32_overlapped_operation_cancellable<socket_accept_operation_cancellable>(std::move(ct))
0089                 , m_impl(listeningSocket, acceptingSocket)
0090             {}
0091 
0092         private:
0093 
0094             friend class cppcoro::detail::win32_overlapped_operation_cancellable<socket_accept_operation_cancellable>;
0095 
0096             bool try_start() noexcept { return m_impl.try_start(*this); }
0097             void cancel() noexcept { m_impl.cancel(*this); }
0098             void get_result() { m_impl.get_result(*this); }
0099 
0100             socket_accept_operation_impl m_impl;
0101 
0102         };
0103     }
0104 }
0105 
0106 #endif // CPPCORO_OS_WINNT
0107 
0108 #endif