void seedArm_service_impl::closeSocket(connection::ptr spConn)
	{
		boost::weak_ptr<connection> wp = spConn;
		if (!wp.expired() && wp.lock() != nullptr)
		{
			try {
				boost::system::error_code ec_;
				spConn->socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec_);

				if(!ec_ && spConn->get_status() == connection::status::closing)
				{
					spConn->set_status(connection::status::close);
					_receiver.onClose(spConn);
				}
				else
				{
					std::cout << "status check : " << ec_.message().data() << std::endl;
				}
			}catch(std::exception e) {
				std::cout << "exception in seedArm_service_impl::closeSocket() => " << e.what() << std::endl;
			}
		}
		else
		{
			std::cout << "seedArm_service_impl::closeSocket(). already expired" << std::endl;
		}
	}
Example #2
0
void Server::start()
{
    std::cout << "Starting server..." << std::endl;
    _status = AVAILABLE;

    Connection::ptr newConnect = Connection::new_( *this );
    _acceptor.async_accept( newConnect->socket(),
    boost::bind( &Server::handleAccept, this, newConnect, _1 ) );
}
Example #3
0
void Server::handleAccept( Connection::ptr connect, const boost::system::error_code& err )
{
    std::cout << "Handling accept..." << std::endl;
    connect->start();

	Connection::ptr newConnect = Connection::new_( *this );
	_acceptor.async_accept( newConnect->socket(),
    boost::bind( &Server::handleAccept, this, newConnect, _1 ) );
}
Example #4
0
void Connection::resend( Stanza st )
{
    std::cout << "Resend to " << st.getTo().getNode() << std::endl;

    //To do offline write to Data structure.

    Connection::ptr target = std::get<1>(*(_myServer.connections().find( st.getTo().getNode() ) ) ); // online
    target->_received.push_back( st );

    if ( target->_isWaiting && !target->_isWriting  )
        target->doWrite();
}
Example #5
0
void Server::addConnection( Connection::ptr newConnection )
{
    std::cout << "Connection added to the list..." << std::endl;

    _connections.insert( std::pair<std::string, Connection::ptr> ( newConnection->getLogin(), newConnection ) );
    _clientsChanged = true;
}
	void seedArm_service_impl::msgEnque(connection::ptr spConn, message::ptr msg)
	{
		_ios.post(
			spConn->strand().wrap(boost::bind(
				&seedArm_service_impl::dispatch
				, this
				, spConn
				, msg)));
	}
	void seedArm_service_impl::close(connection::ptr spConn)
	{
		spConn->set_status(connection::status::closing);

		_ios.post(
			_strand.wrap(boost::bind(
				&seedArm_service_impl::closeSocket
				, this
				, spConn)));
	}