Serial-TCP/IPbridge  1.0
tcpip_connection.h
Go to the documentation of this file.
1 
12 #ifndef TCPIP_CONNECTION_H
13 #define TCPIP_CONNECTION_H
14 
15 #include <tr1/cstdint>
16 #include <unistd.h>
17 #include <arpa/inet.h>
18 #include <netinet/in.h>
19 
20 #include "connection.h"
21 #include "tcpip_config.h"
22 
30 class TCPIPConnection: public Connection {
31  public:
32  friend class TCPIPServer;
33 
34  public:
38  virtual ~TCPIPConnection();
39 
43  std::string getAddress() const;
44 
48  unsigned getPort() const;
49 
50  // Override
51  virtual void close();
52 
53  private:
61  TCPIPConnection(int socket, sockaddr_in socketInfo, const TCPIPConfig &config);
62 
63  // Override.
64  virtual std::string doReceiveMessage(Config::LengthFieldMessageLength messageLength);
65 
66  // Override.
67  virtual size_t doSendMessage(const std::string &message);
68 
69  // Disable copy ctor and assignment operator since this is
70  // a reference object
73 
74  private:
76  int _socket;
78  sockaddr_in _socketInfo;
79 
80  private:
82  static const size_t DEFAULT_LENGTH_FIELD_BUFFER_SIZE = 4096;
83 };
84 
85 #endif // #ifndef TCPIP_CONNECTION_H
86 
87 // End of file tcpip_connection.h
virtual ~TCPIPConnection()
Destructor.
TCPIP server that accepts client connections.
Definition: tcpip_server.h:30
Connection class - declarations.
TCPIPConnection & operator=(const TCPIPConnection &)
TCP/IP connection.
Definition: tcpip_connection.h:30
static const size_t DEFAULT_LENGTH_FIELD_BUFFER_SIZE
Default buffer size used when receiving a message via length_field.
Definition: tcpip_connection.h:82
virtual size_t doSendMessage(const std::string &message)
Sends the selected message.
TCPIPConfig class - declarations.
TCPIPConnection(int socket, sockaddr_in socketInfo, const TCPIPConfig &config)
Constructor.
std::string getAddress() const
Returns IPv4 address of the connected node.
unsigned getPort() const
Returns port number through which the connected node is connected.
sockaddr_in _socketInfo
Socket information.
Definition: tcpip_connection.h:78
Configuration for a TCP/IP server.
Definition: tcpip_config.h:30
std::tr1::uint32_t LengthFieldMessageLength
Message length type when using length field.
Definition: config.h:49
virtual void close()
Closes an established TCP connection.
virtual std::string doReceiveMessage(Config::LengthFieldMessageLength messageLength)
Receives a message.
Abstract class for all connection types.
Definition: connection.h:28
int _socket
Connection socket.
Definition: tcpip_connection.h:76