Beispiel #1
0
void conn_base::accept(tcp::acceptor& acceptor)
{
  if (_socket.is_open()) return;
  acceptor.async_accept(_socket,
      bind(&conn_base::_handle_init, this, _1));
  ++_op_cnt;
}
Beispiel #2
0
	void listen()
	{
		DEBUG_MSG("!==============================================================!");

		////Critical Section
		static std::mutex m;
		std::lock_guard<std::mutex> lock(m);

		sessionPtr newSession = std::make_shared<CSerSession>(io_, mng_);

		try
		{
			acceptor_.async_accept(newSession->socket(), std::bind(&CServer::handle_accept, /*shared_from_this()*/ this, newSession,
				std::placeholders::_1));
			///*boost::system::error_code ec;
			//pSocket_->shutdown(asio::ip::tcp::socket::shutdown_send, ec);*/
		}
		catch (const std::bad_weak_ptr& e)
		{
			DEBUG_MSG(e.what());
			throw e;
		}

		DEBUG_MSG("Listen Activated");
	}
	void thread_fun()
	{
		for (;;)
		{
			error_code ec;
			tcp::endpoint from;
			tcp::socket socket(m_ios);
			condition_variable cond;
			bool done = false;
			m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
			while (!done)
			{
				m_ios.run_one();
				m_ios.reset();
			}

			if (ec == boost::asio::error::operation_aborted
				|| ec == boost::asio::error::bad_descriptor) return;

			if (ec)
			{
				fprintf(stderr, "Error accepting connection on peer socket: %s\n", ec.message().c_str());
				return;
			}

			fprintf(stderr, "%s: incoming peer connection\n", time_now_string());
			++m_peer_requests;
			socket.close(ec);
		}
	}
Beispiel #4
0
 void accept_a_client() {
     acceptor_.async_accept(socket_, peer_, [&](const asio::error_code& error) {
         if(!error) {
             std::make_shared<SimSession>(std::move(socket_), std::move(peer_))->start();
         }
         accept_a_client();
     });
 }
Beispiel #5
0
 server(boost::asio::io_service &io_service, short port, std::string str) :
         io_service_(io_service),
         acceptor_(io_service, tcp::endpoint(boost::asio::ip::address::from_string(str.c_str()), port)) {
     session *new_session = new session(io_service_);
     acceptor_.async_accept(new_session->scoket(),
                            boost::bind(&server::handle_accept, this, new_session,
                                        boost::asio::placeholders::error));
 }
	void start_accept()
	{
		tcp_connection::pointer new_connection = tcp_connection::create(acceptor_.get_io_service());

		acceptor_.async_accept(new_connection->socket(),
			boost::bind(&tcp_server::handle_accept, this, new_connection,
			boost::asio::placeholders::error));
	}
Beispiel #7
0
 void start_accept()
 {
     fprintf(stderr, "server::start_accept()\n");
     session * new_session = new session(io_service_);
     acceptor_.async_accept(new_session->socket(),
             boost::bind(&server::handle_accept, this, new_session,
                 boost::asio::placeholders::error));
 }
Beispiel #8
0
 ChannelServer(boost::asio::io_service& io_service, SocketPartyData me, SocketPartyData other) :
     io_service_server(io_service), io_service_client(io_service),
     acceptor_(io_service, tcp::endpoint(tcp::v4(), me.getPort()))
 {
     Logger::log("Craeting ChannelServer Between me (" + me.to_log_string() + ") and other (" + other.to_log_string() + ")");
     channel = new NativeChannel(io_service_server, io_service_client, me, other);
     acceptor_.async_accept(channel->getServerSocket(), boost::bind(&ChannelServer::handle_accept,
                            this, channel, boost::asio::placeholders::error));
 };
Beispiel #9
0
void server::start_accept()
{

	session* new_session = new session(io_service_);
	new_session->SetServer(this);
	acceptor_.async_accept(new_session->socket(),
		boost::bind(&server::handle_accept, this, new_session,
		boost::asio::placeholders::error));
	
}
Beispiel #10
0
    void add_client(boost::system::error_code ec) {
        if (!ec) {
            boost::lock_guard<boost::mutex> lk(mx);
            connections.push_back(std::move(ss)); 
        }

        if (ec != boost::asio::error::operation_aborted) {
            acceptor.async_accept(ss, boost::bind(&Server::add_client, this, boost::asio::placeholders::error));
        }
    }
 void
 do_accept()
 {
     acceptor_.async_accept(
         socket_,
         std::bind(
             &listener::on_accept,
             shared_from_this(),
             std::placeholders::_1));
 }
Beispiel #12
0
 Server(int serverPort = 6767) : 
     iosvc(),
     work(boost::asio::io_service::work(iosvc)),
     data_worker(&Server::generate_jobs, this),
     io_worker(boost::bind(&boost::asio::io_service::run, &iosvc)),
     acceptor(iosvc, tcp::endpoint(tcp::v4(), serverPort)),
     ss(iosvc)
 {
     acceptor.async_accept(ss, boost::bind(&Server::add_client, this, boost::asio::placeholders::error));
 }
Beispiel #13
0
    void accept() {
        acceptor_.async_accept(socket_,
                               [this](const boost::system::error_code &ec)
        {
            if (!ec) {
                std::make_shared<session>(std::move(socket_))->start();
            }

            accept();
        });
    }
Beispiel #14
0
 void handle_accept(session *new_session,
                    const boost::system::error_code error) {
     if (!error) {
         new_session->start();
         new_session = new session(io_service_);
         acceptor_.async_accept(new_session->scoket(),
                                boost::bind(&server::handle_accept, this, new_session,
                                            boost::asio::placeholders::error));
     } else {
         delete new_session;
     }
 }
Beispiel #15
0
awaitable<void> listener(tcp::acceptor acceptor)
{
  chat_room room;

  for (;;)
  {
    std::make_shared<chat_session>(
        co_await acceptor.async_accept(use_awaitable),
        room
      )->start();
  }
}
Beispiel #16
0
 void _accept( void ){
     Connection::Pointer connection( new Connection( m_ioService ) );
     m_acceptor.async_accept(
         connection->getSocket(),
         boost::bind(
             &Server::_acceptHandler,
             this,
             boost::asio::placeholders::error,
             connection
         )
     );
 }
Beispiel #17
0
void chat_server::do_accept()
{
	acceptor_.async_accept(socket_,
		[this](boost::system::error_code ec)
	{
		if (!ec)
		{
			std::make_shared<chat_session>(std::move(socket_), room_, *this)->start();
		}

		do_accept();
	});
}
Beispiel #18
0
awaitable<void> listener(tcp::acceptor acceptor)
{
  auto token = co_await this_coro::token();

  chat_room room;

  for (;;)
  {
    std::make_shared<chat_session>(
        co_await acceptor.async_accept(token),
        room
      )->start();
  }
}
Beispiel #19
0
void worker::do_accept(tcp::acceptor& acceptor, server& srv) {
    while (acceptor.is_open()) {
        bs::error_code ec;
        // get an io service to use for a new client, we pick them via round robin
        auto& worker = srv.impl()->get_worker();
        auto& iosvc = worker.io_service();
        auto new_session = std::make_shared<session>(srv, iosvc);
        acceptor.async_accept(new_session->socket(), bfa::yield[ec]);
        if (!ec) {
            worker.add_session(new_session);
            worker.m_new_session_cv.notify_one();
        }
    }
}
Beispiel #20
0
    void start_accept()
    {
        // Create a new connection to handle a client. Passing a reference
        // to db to each connection poses no problem since the server is 
        // single-threaded.
        //
        DbConnection::Pointer new_connection = 
            DbConnection::create(acceptor.get_io_service());

        // Asynchronously wait to accept a new client
        //
        acceptor.async_accept(new_connection->get_socket(),
            boost::bind(&DbServerImpl::handle_accept, this, new_connection,
                asio::placeholders::error));
    }
Beispiel #21
0
/*****************************************************************************
*   listening server
*****************************************************************************/
void server( boost::asio::io_service & io_svc, tcp::acceptor & a) {
    print( tag(), ": echo-server started");
    try {
        for (;;) {
            socket_ptr socket( new tcp::socket( io_svc) );
            boost::system::error_code ec;
            a.async_accept(
                    * socket,
                    boost::fibers::asio::yield[ec]);
            if ( ec) {
                throw boost::system::system_error( ec); //some other error
            } else {
                boost::fibers::fiber( session, socket).detach();
            }
        }
    } catch ( std::exception const& ex) {
        print( tag(), ": caught exception : ", ex.what());
    }
    io_svc.stop();
    print( tag(), ": echo-server stopped");
}
Beispiel #22
0
	void accept()
	{
		auto self = shared_from_this();
		awaitingConnection = std::make_shared<Connection>(io);
		acceptor.async_accept(awaitingConnection->stream1(),
			[this, self] (const error_code &error) {
				if (error) {
					std::cerr << "accept: " << error << std::endl;
				} else {
					Connection::Ptr thisConnecion;
					std::swap(thisConnecion, awaitingConnection);
					accept();

					error_code localSocketError;
					thisConnecion->stream2().connect(socketPath, localSocketError);
					if (localSocketError) {
						std::cerr << "connecting local socket: " << localSocketError << std::endl;
						thisConnecion->stream1().close(localSocketError);
						return;
					}
					thisConnecion->start();
				}
			});
	}
Beispiel #23
0
	void start_accept()
	{
		shared_ptr<session> s(new session(acceptor_.io_service(),cache,sessions));
		acceptor_.async_accept(s->socket_,boost::bind(&tcp_cache_server::on_accept,this,aio::placeholders::error,s));
	}
Beispiel #24
0
void TcpServer::start()
{
	TcpConnection::SP_TCPCONNECTION spConnection = TcpConnection::create(m_acceptor.get_io_service());
	m_acceptor.async_accept(spConnection->socket(),
		boost::bind(&TcpServer::OnAccept, this, spConnection, boost::asio::placeholders::error));
}