AdsLib
Loading...
Searching...
No Matches
Sockets.h
1// SPDX-License-Identifier: MIT
6#pragma once
7
8#include "Frame.h"
9#include "wrap_socket.h"
10#include <stdexcept>
11#include <string>
12
13namespace bhf
14{
15namespace ads
16{
17using AddressList = std::unique_ptr<struct addrinfo, void (*)(struct addrinfo*)>;
22AddressList GetListOfAddresses(const std::string& hostPort, const std::string& defaultPort = {});
23}
24}
25
26struct IpV4 {
27 const uint32_t value;
28 IpV4(const std::string& addr);
29 IpV4(uint32_t __val);
30 bool operator<(const IpV4& ref) const;
31 bool operator==(const IpV4& ref) const;
32};
33
34struct Socket {
35 Frame& read(Frame& frame, timeval* timeout) const;
36 size_t read(uint8_t* buffer, size_t maxBytes, timeval* timeout) const;
37 size_t write(const Frame& frame) const;
38 void Shutdown();
39
40 struct TimeoutEx : std::runtime_error {
41 TimeoutEx(const char* _Message) : std::runtime_error(_Message)
42 {}
43 };
44
45protected:
46 int m_WSAInitialized;
47 SOCKET m_Socket;
48 sockaddr_storage m_SockAddress;
49 const sockaddr* const m_DestAddr;
50 socklen_t m_DestAddrLen;
51
52 Socket(const struct addrinfo* host, int type);
53 ~Socket();
54 bool Select(timeval* timeout) const;
55};
56
57struct TcpSocket : Socket {
58 TcpSocket(const struct addrinfo* host);
59 uint32_t Connect() const;
60
67 bool IsConnectedTo(const struct addrinfo* targetAddresses) const;
68};
69
70struct UdpSocket : Socket {
71 UdpSocket(const struct addrinfo* host);
72};
Definition: AdsDef.h:21
Definition: Frame.h:11
Definition: Sockets.h:26
Definition: Sockets.h:40
Definition: Sockets.h:34
Definition: Sockets.h:57
bool IsConnectedTo(const struct addrinfo *targetAddresses) const
Definition: Sockets.cpp:262
Definition: Sockets.h:70