4#ifndef _Stroika_Foundation_IO_Network_Socket_h_
5#define _Stroika_Foundation_IO_Network_Socket_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
11#if qStroika_Platform_POSIX
12#include <sys/socket.h>
16#include "Stroika/Foundation/Common/Common.h"
18#include "Stroika/Foundation/Execution/Exceptions.h"
19#include "Stroika/Foundation/IO/Network/SocketAddress.h"
20#if qStroika_Platform_Windows
21#include "Stroika/Foundation/IO/Network/Platform/Windows/WinSock.h"
24#if qStroika_Platform_Linux or qStroika_Platform_MacOS
36 using Characters::String;
80#if qStroika_Platform_Windows
145 bool fSO_REUSEADDR{
false};
150 enum class ShutdownTarget {
221 Ptr (
Ptr&& s)
noexcept =
default;
226 Ptr (shared_ptr<_IRep>&& rep);
227 Ptr (
const shared_ptr<_IRep>& rep);
240 nonvirtual
void reset () noexcept;
245 nonvirtual
Ptr& operator= (
Ptr&& s) noexcept;
246 nonvirtual
Ptr& operator= (const
Ptr& s);
287 nonvirtual
void Bind (const
SocketAddress& sockAddr, BindFlags bindFlags = BindFlags{});
293 nonvirtual optional<IO::Network::SocketAddress>
GetLocalAddress ()
const;
322 nonvirtual
void Shutdown (ShutdownTarget shutdownTarget = ShutdownTarget::eDEFAULT);
335 nonvirtual
void Close ()
const;
346 nonvirtual
bool IsOpen ()
const;
351 nonvirtual
bool operator== (
const Ptr& rhs)
const;
356 nonvirtual strong_ordering operator<=> (
const Ptr&)
const;
375 template <
typename RESULT_TYPE>
376 nonvirtual RESULT_TYPE
getsockopt (
int level,
int optname)
const;
390 template <
typename ARG_TYPE>
391 nonvirtual
void setsockopt (
int level,
int optname, ARG_TYPE arg)
const;
402 nonvirtual shared_ptr<_IRep> _GetSharedRep ()
const;
408 nonvirtual _IRep&
_ref ()
const;
414 nonvirtual
const _IRep&
_cref ()
const;
420 shared_ptr<_IRep> fRep_;
422 static_assert (totally_ordered<Ptr>);
428 virtual ~_IRep () =
default;
429 virtual void Shutdown (ShutdownTarget shutdownTarget) = 0;
430 virtual void Close () = 0;
432 virtual optional<IO::Network::SocketAddress> GetLocalAddress ()
const = 0;
435 virtual void getsockopt (
int level,
int optname,
void* optval, socklen_t* optvallen)
const = 0;
436 virtual void setsockopt (
int level,
int optname,
const void* optval, socklen_t optvallen) = 0;
439 namespace _Protected {
442 const optional<IPPROTO>& protocol);
446#if qStroika_Platform_Windows
455 template <
typename INT_TYPE>
456 INT_TYPE ThrowWSASystemErrorIfSOCKET_ERROR (INT_TYPE returnCode)
457 requires (is_signed_v<INT_TYPE>);
463namespace Stroika::Foundation::Execution::WaitForIOReady_Support {
466 template <
typename T>
467 struct WaitForIOReady_Traits;
469 struct WaitForIOReady_Traits<IO::Network::Socket::Ptr> {
471 static inline auto GetSDKPollable (
const HighLevelType& t)
#define Stroika_Define_Enum_Bounds(FIRST_ITEM, LAST_ITEM)
#define Stroika_ATTRIBUTE_NO_UNIQUE_ADDRESS_VCFORCE
[[msvc::no_unique_address]] isn't always broken in MSVC. Annotate with this on things where its not b...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
NOT a real mutex - just a debugging infrastructure support tool so in debug builds can be assured thr...
a smart pointer wrapper (like shared_ptr <_IRep>).
Ptr(const Ptr &s)=default
nonvirtual RESULT_TYPE getsockopt(int level, int optname) const
nonvirtual PlatformNativeHandle Detach()
nonvirtual void Bind(const SocketAddress &sockAddr, BindFlags bindFlags=BindFlags{})
nonvirtual void setsockopt(int level, int optname, ARG_TYPE arg) const
nonvirtual SocketAddress::FamilyType GetAddressFamily() const
nonvirtual void reset() noexcept
nonvirtual void Shutdown(ShutdownTarget shutdownTarget=ShutdownTarget::eDEFAULT)
nonvirtual _IRep & _ref() const
nonvirtual optional< IO::Network::SocketAddress > GetLocalAddress() const
nonvirtual PlatformNativeHandle GetNativeSocket() const
nonvirtual const _IRep & _cref() const
nonvirtual void Close() const
nonvirtual bool IsOpen() const
nonvirtual String ToString() const
nonvirtual Type GetType() const
FamilyType
Socket address family - also sometimes referred to as domain (argument to ::socket calls it domain)