23 #ifndef C_TCP_SERVER_HPP 24 #define C_TCP_SERVER_HPP 26 #include <boost/asio.hpp> 27 #include <boost/function.hpp> 28 #include <boost/shared_ptr.hpp> 29 #include <boost/noncopyable.hpp> 42 :
private boost::noncopyable
46 typedef boost::shared_ptr<CTcpServer>
Pointer;
49 typedef boost::shared_ptr<boost::asio::ip::tcp::socket>
Connection;
58 static Pointer
Create(boost::asio::io_service & ios,
unsigned short port,
59 const std::string address=
"");
74 CTcpServer(boost::asio::io_service & ios,
unsigned short port,
75 const std::string address=
"");
78 void HandleAccept(
const boost::system::error_code & error);
81 std::string
hdr()
const;
100 #endif // C_TCP_SERVER_HPP TCP server that handles a single client connection.
Definition: CTcpServer.hpp:41
boost::asio::ip::tcp::acceptor m_acceptor
Acceptor for new client connections.
Definition: CTcpServer.hpp:84
void Stop()
Stops the TCP server.
Definition: CTcpServer.cpp:133
unsigned short m_port
Port number of the server.
Definition: CTcpServer.hpp:87
void HandleAccept(const boost::system::error_code &error)
Handles an accepted client connection.
Definition: CTcpServer.cpp:212
ConnectionHandler m_handler
Callback function to handle clients.
Definition: CTcpServer.hpp:90
Connection m_client
Socket for the current client.
Definition: CTcpServer.hpp:93
static Pointer Create(boost::asio::io_service &ios, unsigned short port, const std::string address="")
Creates a new TCP server on the specified port number.
Definition: CTcpServer.cpp:117
boost::function< void()> ConnectionHandler
Type of the callback function for client connections.
Definition: CTcpServer.hpp:52
std::string hdr() const
Gets a log header.
Definition: CTcpServer.cpp:241
CTcpServer(boost::asio::io_service &ios, unsigned short port, const std::string address="")
Constructs the TCP server on the specified port number.
Definition: CTcpServer.cpp:65
void RegisterHandler(ConnectionHandler h)
Registers a callback function for client connections.
Definition: CTcpServer.cpp:157
void StartAccept()
Prepares to accept the next client.
Definition: CTcpServer.cpp:184
boost::shared_ptr< CTcpServer > Pointer
Convenience type for a shared pointer to self.
Definition: CTcpServer.hpp:46
General FREEDM Namespace.
Definition: CBroker.cpp:53
Connection GetClient()
Gets the current client.
Definition: CTcpServer.hpp:71
boost::shared_ptr< boost::asio::ip::tcp::socket > Connection
Convenient type for the client socket.
Definition: CTcpServer.hpp:49
virtual ~CTcpServer()
Virtual destructor for derived classes.
Definition: CTcpServer.cpp:99