TDME2  1.9.200
NetworkSocket.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
8 
9 using std::string;
10 
12 
13 /**
14  * Base class of network sockets
15  * @author Andreas Drewke
16  */
18  friend class KernelEventMechanism;
19 
20 public:
21  enum IpVersion {IPV4, IPV6};
22 
23  /**
24  * Determine IP version
25  * @param ip ip
26  * @returns ip version
27  */
28  static IpVersion determineIpVersion(const string& ip);
29 
30  // forbid class copy
32 
33  /**
34  * Protected constructor
35  */
36  NetworkSocket();
37 
38  /**
39  * @brief public destructor
40  */
41  virtual ~NetworkSocket();
42 
43  /**
44  * @brief returns the end points ip address
45  * @return end point ip address
46  */
47  const string& getAddress();
48 
49  /**
50  * @brief returns the end points port
51  * @return end point port
52  */
53  const unsigned int getPort();
54 
55  /**
56  * Binds a socket to local ip and port
57  * @param ip ip
58  * @param port port
59  * @throws tdme::os::network::NetworkSocketException
60  */
61  void bind(const string& ip, const unsigned int port);
62 
63  /**
64  * @brief sets the socket non blocked
65  * @throws tdme::os::network::NetworkSocketException
66  */
67  void setNonBlocked();
68 
69  /**
70  * @brief shuts socket down for reading and writing
71  */
72  virtual void shutdown();
73 
74  /**
75  * Closes the socket
76  */
77  virtual void close();
78 
79 protected:
81  string ip;
82  unsigned int port;
83 };
84 
85 // MINGW: Have some missing posix functions
86 #if defined(__MINGW32__) && !defined(__MINGW64__)
87  // TODO: move those somewhere else as they are not only socket specific
88  #define inet_pton inet_pton6
89  #define inet_ntop inet_ntop6
90  size_t strlcpy(char* __restrict dst, const char* __restrict src, size_t siz);
91  int inet_pton4(const char* src, void* dst);
92  int inet_pton6(int af, const char* src, void* dst);
93  char* inet_ntop4(const void* src, char* dst, size_t size);
94  char* inet_ntop6(int af, const void* src, char* dst, size_t size);
95 #endif
Interface to kernel event mechanismns.
Base class of network sockets.
Definition: NetworkSocket.h:17
void bind(const string &ip, const unsigned int port)
Binds a socket to local ip and port.
virtual void close()
Closes the socket.
virtual void shutdown()
shuts socket down for reading and writing
static IpVersion determineIpVersion(const string &ip)
Determine IP version.
const string & getAddress()
returns the end points ip address
void setNonBlocked()
sets the socket non blocked
const unsigned int getPort()
returns the end points port
virtual ~NetworkSocket()
public destructor
NetworkSocket()
Protected constructor.
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6