Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 13th, 2011  |  syntax: C++  |  size: 0.88 KB  |  hits: 72  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "server.h"
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. server::server(boost::asio::io_service& io_service, short port)
  7.            : io_service_(io_service)
  8.            , acceptor_(io_service, tcp::endpoint(tcp::v4(), port))
  9. {
  10.         session* new_session = new session(io_service_);
  11.         acceptor_.async_accept(new_session->socket(),
  12.                 boost::bind(&server::handle_accept, this, new_session,
  13.                 boost::asio::placeholders::error));
  14. }
  15.  
  16. void server::handle_accept(session* new_session,
  17.                                                    const boost::system::error_code& error)
  18. {
  19.         if (!error)
  20.         {
  21.                 cout << "connection from "
  22.                          << new_session->socket().remote_endpoint()
  23.                          << endl;
  24.                 new_session->start();
  25.                 new_session = new session(io_service_);
  26.                 acceptor_.async_accept(new_session->socket(),
  27.                         boost::bind(&server::handle_accept, this, new_session,
  28.                         boost::asio::placeholders::error));
  29.         }
  30.         else
  31.         {
  32.                 delete new_session;
  33.         }
  34. }