simple-socket library 1.9.0
Loading...
Searching...
No Matches
InternetSocket.h
Go to the documentation of this file.
1#ifndef NET_InternetSocket_h__
2#define NET_InternetSocket_h__
3
4#include "SimpleSocket.h"
5
6namespace NET
7{
9
17 {
18 public:
20
28 void setReuseAddress( bool enable);
29
31
44 ConnectResult connect( std::string_view foreignAddress, unsigned short foreignPort);
45
47
57 ConnectResult timedConnect( std::string_view foreignAddress, unsigned short foreignPort, int timeout);
58
64 void bind( unsigned short localPort = 0);
65
67
86 void bind( std::string_view localAddress, unsigned short localPort = 0);
87
93 std::string getLocalAddress() const;
94
100 unsigned short getLocalPort() const;
101
107 std::string getForeignAddress() const;
108
114 unsigned short getForeignPort() const;
115
117 AddressFamily addressFamily() const noexcept { return m_family; }
118
119 protected:
121 InternetSocket( AddressFamily family, int type, int protocol);
122
124 InternetSocket( AdoptSocketTag, int sockfd, int type);
125
126 InternetSocket( InternetSocket&& other) noexcept = default;
127 InternetSocket& operator=( InternetSocket&& other) noexcept = default;
128
129 // IPv4 or IPv6
131 };
132
133} // namespace NET
134
135#endif // NET_InternetSocket_h__
void bind(std::string_view localAddress, unsigned short localPort=0)
bind socket to address / port
unsigned short getLocalPort() const
InternetSocket(AdoptSocketTag, int sockfd, int type)
allows a subclass to take ownership of an existing socket
void bind(unsigned short localPort=0)
std::string getForeignAddress() const
InternetSocket(AddressFamily family, int type, int protocol)
allows a subclass to create new socket
std::string getLocalAddress() const
unsigned short getForeignPort() const
AddressFamily m_family
AddressFamily addressFamily() const noexcept
return wether this socket was created for IPv4 or IPv6
ConnectResult timedConnect(std::string_view foreignAddress, unsigned short foreignPort, int timeout)
establish a connection with the given foreign address and port
InternetSocket & operator=(InternetSocket &&other) noexcept=default
InternetSocket(InternetSocket &&other) noexcept=default
ConnectResult connect(std::string_view foreignAddress, unsigned short foreignPort)
establish a connection with the given foreign address and port
void setReuseAddress(bool enable)
Enable or disable local address reuse.
SimpleSocket(const SimpleSocket &)=delete
AddressFamily
used by internet socket types
ConnectResult
result of the connection attempt
used to safely adopt internal socket descriptor