simple-socket library 1.5.0
Loading...
Searching...
No Matches
InternetSocket.h
1#ifndef NET_InternetSocket_h__
2#define NET_InternetSocket_h__
3
4#include "SimpleSocket.h"
5
6namespace NET
7{
9
16 class InternetSocket : public SimpleSocket
17 {
18 public:
20
28 void setReuseAddress( bool enable);
29
31
43 void connect( std::string_view foreignAddress, unsigned short foreignPort);
44
46
57 int 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 explicit InternetSocket( int sockfd);
122
124 InternetSocket( AddressFamily family, int type, int protocol);
125
126 // IPv4 or IPv6
127 AddressFamily m_family;
128 };
129
130} // namespace NET
131
132#endif // NET_InternetSocket_h__
void bind(unsigned short localPort=0)
unsigned short getLocalPort() const
unsigned short getForeignPort() const
InternetSocket(int sockfd)
create socket from a SocketHandle returned by an accept() call
int timedConnect(std::string_view foreignAddress, unsigned short foreignPort, int timeout)
establish a connection with the given foreign address and port
void setReuseAddress(bool enable)
Enable or disable local address reuse.
AddressFamily addressFamily() const noexcept
return wether this socket was created for IPv4 or IPv6
void connect(std::string_view foreignAddress, unsigned short foreignPort)
establish a connection with the given foreign address and port
std::string getLocalAddress() const
std::string getForeignAddress() const