diff options
author | Vegard Storheil Eriksen <zyp@sakuya.local> | 2010-11-06 02:35:39 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@sakuya.local> | 2010-11-06 02:35:39 +0100 |
commit | cfef24ce8541ac3934ecfe7248a33d1099d94dfa (patch) | |
tree | 4335e25b6fd490fa8744fed82aa7273fc7a72395 /server/tcpserver.cpp | |
parent | df5932614261a825fb5a9283c321f47f7a198b24 (diff) |
First take on abstract ConnectionBase, ASIO listening and connection handling.
Diffstat (limited to 'server/tcpserver.cpp')
-rw-r--r-- | server/tcpserver.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/server/tcpserver.cpp b/server/tcpserver.cpp new file mode 100644 index 0000000..528d1a2 --- /dev/null +++ b/server/tcpserver.cpp @@ -0,0 +1,28 @@ +#include "tcpserver.h" + +#include <boost/bind.hpp> + +TCPServer::TCPServer(boost::asio::io_service& io_service) + : acceptor_(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 12345)) { + + // Start listening for first connection attempt. + listen(); +} + +void TCPServer::listen() { + Connection::p new_connection = Connection::create(acceptor_.io_service()); + + acceptor_.async_accept(new_connection->socket, + boost::bind(&TCPServer::handle_connection, this, new_connection, boost::asio::placeholders::error)); +} + +void TCPServer::handle_connection(Connection::p connection, const boost::system::error_code& error) { + if(error) { + return; + } + + connection->connected(); + + // Start listening for another connection attempt. + listen(); +}
\ No newline at end of file |