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_Foundation_Common_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_Foundation_Common_Platform_Windows
21#include "Stroika/Foundation/IO/Network/Platform/Windows/WinSock.h"
24#if qStroika_Foundation_Common_Platform_Linux or qStroika_Foundation_Common_Platform_MacOS
36 using Characters::String;
80#if qStroika_Foundation_Common_Platform_Windows
113 bool fSO_REUSEADDR{
false};
118 enum class ShutdownTarget {
189 Ptr (
Ptr&& s)
noexcept =
default;
194 Ptr (shared_ptr<_IRep>&& rep);
195 Ptr (
const shared_ptr<_IRep>& rep);
208 nonvirtual
void reset () noexcept;
213 nonvirtual
Ptr& operator= (
Ptr&& s) noexcept;
214 nonvirtual
Ptr& operator= (const
Ptr& s);
255 nonvirtual
void Bind (const
SocketAddress& sockAddr, BindFlags bindFlags = BindFlags{});
261 nonvirtual optional<IO::Network::SocketAddress>
GetLocalAddress ()
const;
290 nonvirtual
void Shutdown (ShutdownTarget shutdownTarget = ShutdownTarget::eDEFAULT);
303 nonvirtual
void Close ()
const;
314 nonvirtual
bool IsOpen ()
const;
319 nonvirtual
bool operator== (
const Ptr& rhs)
const;
324 nonvirtual strong_ordering operator<=> (
const Ptr&)
const;
343 template <
typename RESULT_TYPE>
344 nonvirtual RESULT_TYPE
getsockopt (
int level,
int optname)
const;
358 template <
typename ARG_TYPE>
359 nonvirtual
void setsockopt (
int level,
int optname, ARG_TYPE arg)
const;
370 nonvirtual shared_ptr<_IRep> _GetSharedRep ()
const;
376 nonvirtual _IRep&
_ref ()
const;
382 nonvirtual
const _IRep&
_cref ()
const;
388 shared_ptr<_IRep> fRep_;
390 static_assert (totally_ordered<Ptr>);
396 virtual ~_IRep () =
default;
397 virtual void Shutdown (ShutdownTarget shutdownTarget) = 0;
398 virtual void Close () = 0;
400 virtual optional<IO::Network::SocketAddress> GetLocalAddress ()
const = 0;
403 virtual void getsockopt (
int level,
int optname,
void* optval, socklen_t* optvallen)
const = 0;
404 virtual void setsockopt (
int level,
int optname,
const void* optval, socklen_t optvallen) = 0;
407 namespace _Protected {
410 const optional<IPPROTO>& protocol);
414#if qStroika_Foundation_Common_Platform_Windows
423 template <
typename INT_TYPE>
424 INT_TYPE ThrowWSASystemErrorIfSOCKET_ERROR (INT_TYPE returnCode)
425 requires (is_signed_v<INT_TYPE>);
434 template <
typename T>
435 struct WaitForIOReady_Traits;
437 struct WaitForIOReady_Traits<IO::Network::Socket::Ptr> {
439 static inline auto GetSDKPollable (
const HighLevelType& t)
#define Stroika_Define_Enum_Bounds(FIRST_ITEM, LAST_ITEM)
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)