11 #include <boost/asio.hpp>
12 #include <boost/bind.hpp>
13 #include <pion/net/TCPServer.hpp>
14 #include "ShutdownManager.hpp"
18 using namespace pion::net;
26 virtual void handleConnection(TCPConnectionPtr& tcp_conn)
28 static const std::string HELLO_MESSAGE(
"Hello there!\x0D\x0A");
29 tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_CLOSE);
30 tcp_conn->async_write(boost::asio::buffer(HELLO_MESSAGE),
31 boost::bind(&TCPConnection::finish, tcp_conn));
38 int main (
int argc,
char *argv[])
40 static const unsigned int DEFAULT_PORT = 8080;
43 unsigned int port = DEFAULT_PORT;
45 port = strtoul(argv[1], 0, 10);
46 if (port == 0) port = DEFAULT_PORT;
47 }
else if (argc != 1) {
48 std::cerr <<
"usage: PionHelloServer [port]" << std::endl;
54 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
56 signal(SIGINT, handle_signal);
60 PionLogger main_log(PION_GET_LOGGER(
"PionHelloServer"));
62 PION_LOG_SETLEVEL_INFO(main_log);
63 PION_LOG_SETLEVEL_INFO(pion_log);
64 PION_LOG_CONFIG_BASIC;
70 hello_server->start();
71 main_shutdown_manager.wait();
73 }
catch (std::exception& e) {
74 PION_LOG_FATAL(main_log, e.what());