-
Notifications
You must be signed in to change notification settings - Fork 0
/
LedServer.cpp
32 lines (30 loc) · 988 Bytes
/
LedServer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "LedServer.h"
LedServer::LedServer(boost::asio::io_service& io_service, short port, CommandManager* manager)
: io_service_(io_service),
acceptor_(io_service, tcp::endpoint(tcp::v4(), port))
{
manager_ = manager;
Session* new_session = new Session(io_service_, manager);
acceptor_.async_accept(
new_session->socket(),
boost::bind(
&LedServer::handleAccept,
this,
new_session,
boost::asio::placeholders::error
)
);
}
void LedServer::handleAccept(Session* new_session, const boost::system::error_code& error)
{
if (!error) {
new_session->start();
new_session = new Session(io_service_, manager_);
acceptor_.async_accept(
new_session->socket(),
boost::bind(&LedServer::handleAccept, this, new_session, boost::asio::placeholders::error)
);
} else {
delete new_session;
}
}