Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SocketAddress.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
8#include "Stroika/Foundation/Containers/Collection.h"
9#include "Stroika/Foundation/Execution/Exceptions.h"
11
12#include "SocketAddress.h"
13
14using namespace Stroika::Foundation;
15using namespace Stroika::Foundation::Memory;
16using namespace Stroika::Foundation::IO;
18
19/*
20 ********************************************************************************
21 ********************* IO::Network::SocketAddress *******************************
22 ********************************************************************************
23 */
24#if qStroika_Foundation_Common_Platform_Windows
25SocketAddress::SocketAddress (const SOCKET_ADDRESS& sockaddr)
26 : fSocketAddress_{}
27{
28 if (sockaddr.iSockaddrLength > sizeof (fSocketAddressStorage_)) [[unlikely]] {
29 Execution::Throw (Execution::Exception{"bad socket address size"sv});
30 }
31 (void)::memcpy (&fSocketAddressStorage_, sockaddr.lpSockaddr, sockaddr.iSockaddrLength);
32}
33#endif
34
36{
37 if (IsInternetAddress ()) {
38 using namespace Characters::Literals;
39 return Characters::ToString (GetInternetAddress ()) + ":"sv + "{}"_f(GetPort ());
40 }
41 else {
42 return Characters::ToString (Memory::BLOB{reinterpret_cast<const byte*> (&fSocketAddress_),
43 reinterpret_cast<const byte*> (&fSocketAddress_) + GetRequiredSize ()});
44 }
45}
46
47/*
48 ********************************************************************************
49 ********************* IO::Network::SocketAddresses *****************************
50 ********************************************************************************
51 */
53{
55 for (const auto& i : internetAddresses) {
56 tmp += SocketAddress{i, portNumber};
57 }
58 return move (tmp);
59}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A Collection<T> is a container to manage an un-ordered collection of items, without equality defined ...
Definition Collection.h:102
Exception<> is a replacement (subclass) for any std c++ exception class (e.g. the default 'std::excep...
Definition Exceptions.h:157
nonvirtual InternetAddress GetInternetAddress() const
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237
String ToString(T &&t, ARGS... args)
Return a debug-friendly, display version of the argument: not guaranteed parsable or usable except fo...
Definition ToString.inl:465
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...
Definition Throw.inl:43
Traversal::Iterable< SocketAddress > SocketAddresses(const Traversal::Iterable< InternetAddress > &internetAddresses, PortType portNumber)