Serial-TCP/IPbridge  1.0
tcpip_server.h
Go to the documentation of this file.
1 
12 #ifndef TCPIP_SERVER_H
13 #define TCPIP_SERVER_H
14 
15 #include <memory>
16 #include <netinet/in.h>
17 #include <sys/socket.h>
18 
19 #include "tcpip_config.h"
20 #include "tcpip_connection.h"
21 
30 class TCPIPServer {
31  public:
36  public:
37  explicit TCPIPServerError(const std::string &errorMessage):
38  BaseException(errorMessage) {}
39  };
40 
41  public:
54  explicit TCPIPServer(const TCPIPConfig &config);
55 
59  ~TCPIPServer();
60 
73  std::auto_ptr<TCPIPConnection> tryAcceptConnection();
74 
78  void stopListening();
79 
80  private:
82  typedef std::vector<int> Sockets;
83 
85  typedef std::vector<std::string> IPAddresses;
86 
87  private:
88  // Disable copy ctor and assignment operator since this is
89  // a reference object
90  TCPIPServer(const TCPIPServer &);
92 
109 
123  IPAddresses getInterfaceAddresses(const std::string &interface);
124 
125  private:
130 
132  static const int MAX_CONNECTION_COUNT;
133 };
134 
135 #endif // #ifndef TCPIP_SERVER_H
136 
137 // End of file tcpip_server.h
IPAddresses getInterfaceAddresses(const std::string &interface)
Returns all IPv4 address associated with the selected interface.
TCPIPServer & operator=(const TCPIPServer &)
TCPIPServer(const TCPIPConfig &config)
Constructor.
TCPIPServerError(const std::string &errorMessage)
Definition: tcpip_server.h:37
TCPIP server that accepts client connections.
Definition: tcpip_server.h:30
void stopListening()
Stops listening (accepting new connections).
TCPIPConfig class - declarations.
std::vector< int > Sockets
List of sockets.
Definition: tcpip_server.h:82
static const int MAX_CONNECTION_COUNT
Maximal incoming connection count.
Definition: tcpip_server.h:132
Base exception class for all project exceptions.
Definition: base_exception.h:23
std::vector< std::string > Interfaces
List of network iterfaces.
Definition: tcpip_config.h:33
TCPIPConnection class - declarations.
Configuration for a TCP/IP server.
Definition: tcpip_config.h:30
IPAddresses getAddressesToListenOn(const TCPIPConfig::Interfaces &interfaces)
Returns a list of IPv4 address on which the server should listen on.
Sockets _sockets
List of sockets on which the server listens.
Definition: tcpip_server.h:129
std::vector< std::string > IPAddresses
List of IPv4 addresses.
Definition: tcpip_server.h:85
~TCPIPServer()
Destructor.
std::auto_ptr< TCPIPConnection > tryAcceptConnection()
Tries to accept a TCP/IP connection from a client.
This exception is thrown in case of some server error.
Definition: tcpip_server.h:35
const TCPIPConfig _config
TCP/IP configuration.
Definition: tcpip_server.h:127