コード例 #1
0
ファイル: Server.cpp プロジェクト: longshadian/estl
void Server::handleAcceptError(const boost::system::error_code& ec)
{
    std::cout << "ERROR error reason:" << ec.value() << " "  << ec.message() << std::endl;
    stopAccept();
}
コード例 #2
0
ファイル: SSLSession.cpp プロジェクト: firememory/Whatway
void SSLSession::handle_read_head(const boost::system::error_code& error, size_t bytes_transferred, IMessage* req)
{
	if (error)
	{
		gFileLog::instance().Log("SSLSession 读包头失败, 错误代码:" + boost::lexical_cast<std::string>(error.value()) + ", 错误消息:" + error.message());

		close();
		return;
	}

	if (bytes_transferred != req->GetMsgHeaderSize())
	{
		gFileLog::instance().Log("SSLSession 读包头失败,需要读:" + boost::lexical_cast<std::string>(req->GetMsgHeaderSize()) + ", 实际读:" + boost::lexical_cast<std::string>(bytes_transferred) );

		close();
		return;
	}

	
	if (!req->DecoderMsgHeader())
	{
		gFileLog::instance().Log("SSLSession 解码包头失败");

		close();
		return;
	}

	boost::asio::async_read(socket_, 
		boost::asio::buffer(req->GetMsgContent(), req->GetMsgContentSize()),
		boost::asio::transfer_all(),
		strand_.wrap(
			bind(&SSLSession::handle_read_msg, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, req)
		)
	);
}
コード例 #3
0
void UdpClient::onSend( const string& message, const boost::system::error_code& error, 
	std::size_t bytesTransferred )
{
	OutputDebugStringA( ( error.message() + "\n" ).c_str() );
}
コード例 #4
0
void server_conn::output_error( std::string err_msg, const boost::system::error_code &e )
{
	cerr<<err_msg<<", error message: "<<e.message()<<endl;
}
コード例 #5
0
ファイル: smtp.cpp プロジェクト: 0000-bigtree/nscp
		void smtp_client::connection::got_response(std::string resp, boost::system::error_code ec, size_t bytes) {
			if (ec) {
				NSC_LOG_ERROR("smtp failure in reading: " + ec.message());
				boost::lock_guard<boost::mutex> lg(sc->m);
				if (cur) 
					sc->ready.push_back(cur);
				sc->active_connection.reset();
				return;
			}

			std::string line;
			line.reserve(bytes);
			for (size_t i = 0; i < bytes; i++)
				line += char(readbuf.sbumpc());

			resp += line;

			if (line.length() >= 4 && line[3] == '-') {
				boost::asio::async_read_until(serv, readbuf, "\r\n", boost::bind(&connection::got_response,  shared_from_this(), resp, _1, _2));
				return;
			}
			NSC_DEBUG_MSG("smtp read " + resp);

			bool broken_resp = resp.empty() || !('2' <= resp[0] && resp[0] <= '5') || (resp[0] == '3' && (state != DATA || resp.substr(0,3) != "354"));

			// FIXME deferral / drop-on-the-floor notifications

			if (broken_resp || resp[0] == '4')
			{
				boost::lock_guard<boost::mutex> lg(sc->m);
				if (cur) 
					sc->deferred.push_back(cur);
			}

			if (broken_resp || state == QUIT) {
				NSC_LOG_ERROR("smtp terminating");

				boost::lock_guard<boost::mutex> lg(sc->m);
				sc->active_connection.reset();
				return;
			}

			if ((resp[0] == '4' || resp[0] == '5' || state == DATA_354) && (resp.substr(0,3) != "502" || state != EHLO)) {
				cur.reset();
				if (sc->ready.empty() || state <= RSET) {
					state = QUIT;
					send_line("QUIT");
				} else {
					state = RSET;
					send_line("RSET");
				}
				return;
			}

			assert(!resp.empty());

			switch (state) {
			case BANNER:
				assert(resp[0] == '2');
				state = EHLO;
				send_line("EHLO " + config["canonical-name"]);
				break;
			case EHLO:
				if (resp.substr(0,3) == "502")
				{
					state = HELO;
					send_line("HELO" + config["canonical-name"]);
					break;
				}
				assert(resp[0] == '2');
				/* passthrough */
			case HELO:
			case RSET:
				assert(resp[0] == '2');
				assert(!cur);
				{
					boost::lock_guard<boost::mutex> lg(sc->m);
					if (sc->ready.empty())
					{
						state = QUIT;
						send_line("QUIT");
						break;
					}
					cur = sc->ready.front();
					sc->ready.pop_front();
				}
				assert(cur);
				state = MAIL_FROM;
				send_line("MAIL FROM: <" + cur->sender + ">");
				break;
			case MAIL_FROM:
				assert(resp[0] == '2');
				assert(cur);
				state = RCPT_TO;
				send_line("RCPT TO: <" + cur->recipient + ">");
				break;
			case RCPT_TO:
				assert(resp[0] == '2');
				assert(cur);
				state = DATA;
				send_line("DATA");
				break;
			case DATA:
				assert(resp.substr(0,3) == "354");
				assert(cur);
				state = DATA_354;
				send_raw(cur->data + ".\r\n");
				break;
			case DATA_354: 
			case QUIT:
				assert(0); // handled above
				break;
			}
		}
コード例 #6
0
ファイル: main.cpp プロジェクト: Palmik/bob
inline void error_callback(boost::system::error_code e)
{
    std::cerr << "System error: " << e.message() << std::endl;
    std::exit(1);
}
コード例 #7
0
ファイル: http_client.cpp プロジェクト: dot-Sean/Helix
void HTTPClient::request_failed(const boost::system::error_code& err)
{
    logger << "HTTPClient Request failed: " << err.message() << ".  Retrying." << std::endl;
    abort_request();
}
コード例 #8
0
ファイル: ClientConnection.cpp プロジェクト: vorkostil/vsGame
void ClientConnection::handleRead( const boost::system::error_code& error )
{
	if ( error == 0)
	{
      // invoke a thread to handle the message
      boost::thread worker( &ClientConnection::handleReadInThread,
                            this,
                            message );

		// back to listen
		waitForData();
	}
	else
	{
      // if an error occurs, close the connection
      std::stringstream stream;
      stream << "ClientConnection (" << technicalId << ") > handleRead call with error code: " << error.value() << " --> " << error.message();
      AsyncLogger::getInstance()->log( stream.str() );

      connectionManager->closeConnection( shared_from_this() );
	}
}
コード例 #9
0
ファイル: exceptions.hpp プロジェクト: cokeboL/fibio
 future_error(boost::system::error_code ec)
 : logic_error(ec.message())
 , ec_(ec)
 {}
コード例 #10
0
/* Some error occured at lower levels. Logging it and deactivating the current session seems legit.
 */
void ServerProtocolDispatcher::handle_error(
    boost::system::error_code error)
{
  std::cout << "ServerProtocolDispatcher::handle_error: " << error.message() << std::endl;
  _active = false;
}
コード例 #11
0
ファイル: SSLSession.cpp プロジェクト: firememory/Whatway
void SSLSession::handle_write_msg(const boost::system::error_code& error, size_t bytes_transferred, IMessage* resp)
{

	if (error)
	{

		gFileLog::instance().Log("SSLSession 写包内容失败, 错误代码:" + boost::lexical_cast<std::string>(error.value()) + ", 错误消息:" + error.message());

		close();
		return;
	}

	if (bytes_transferred != resp->GetMsgContentSize())
	{
		gFileLog::instance().Log("SSLSession 写包内容失败 需要写:" + boost::lexical_cast<std::string>(resp->GetMsgContentSize()) + ", 实际写:" + boost::lexical_cast<std::string>(bytes_transferred) );

		close();
		return;
	}

	// 存入日志队列
	resp->SetSendTime();

	gFileLogManager::instance().push(resp->log);
	gDistributedLogManager::instance().push(resp->log);

	/*
	if (resp->GetMsgHeader()->FunctionNo == 0)
	{
		// 心跳功能不写日志
	}
	else
	{
		
	}
	*/

	// 删除应答包
	resp->destroy();
}
コード例 #12
0
ファイル: SSLSession.cpp プロジェクト: firememory/Whatway
void SSLSession::handle_write_head(const boost::system::error_code& error, size_t bytes_transferred, IMessage* resp)
{
	if (error)
	{
		gFileLog::instance().Log("SSLSession 写包头失败,错误代码:" + boost::lexical_cast<std::string>(error.value()) + ", 错误消息:" + error.message());

		close();
		return;
	}


	if (bytes_transferred != resp->GetMsgHeaderSize())
	{
		gFileLog::instance().Log("SSLSession 写包头失败 需要写:" + boost::lexical_cast<std::string>(resp->GetMsgHeaderSize()) + ", 实际写:" + boost::lexical_cast<std::string>(bytes_transferred) );

		close();
		return;
	}

	try
	{
		boost::asio::async_write(socket_,
			boost::asio::buffer(resp->GetMsgContent(), resp->GetMsgContentSize()),
			boost::asio::transfer_all(),
			strand_.wrap(
				bind(&SSLSession::handle_write_msg, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, resp)
			)
		);
	}
	catch(std::exception& e)
	{
		std::string expMsg = e.what();
		gFileLog::instance().Log("SSLSession handle_write_head exp: " + expMsg);
	}
	
}
コード例 #13
0
ファイル: SSLSession.cpp プロジェクト: firememory/Whatway
void SSLSession::handle_read_msg(const boost::system::error_code& error, size_t bytes_transferred, IMessage* req)
{
	
		
	if (error) 
	{
	
		gFileLog::instance().Log("SSLSession 读包内容失败, 错误代码:" + boost::lexical_cast<std::string>(error.value()) + ", 错误消息:" + error.message());

		close();
		return;
	}

	if (bytes_transferred != req->GetMsgContentSize())
	{
		gFileLog::instance().Log("SSLSession 读包内容失败 需要读:" + boost::lexical_cast<std::string>(req->GetMsgContentSize()) + ", 实际读:" + boost::lexical_cast<std::string>(bytes_transferred) );

		close();
		return;
	}

	
	// 设置接收到的时间
	req->SetRecvTime();

	queue_.push(req);

	read();
}
コード例 #14
0
ファイル: Connector.hpp プロジェクト: huangyt/MyProjects
        boost::system::error_code Connector::connect(
            SocketType & peer1, 
            NetName const & netname, 
            boost::system::error_code & ec)
        {
            typedef typename SocketType::protocol_type::socket socket;
            typedef typename socket::endpoint_type endpoint_type;

            socket & peer(peer1); // we should use the real socket type, not the child type

            if (netname.is_digit()) {
                return connect(peer, netname.endpoint(), ec);
            }
            if (!started_) {
                canceled_ = canceled_forever_;
                stat_.reset();
                connect_started_ = false;
                boost::asio::detail::mutex::scoped_lock lock(mutex_);
                if (canceled_) {
                    ec = boost::asio::error::operation_aborted;
                    canceled_ = false;
                } else {
                    lock.unlock();
                    resolver_iterator_ = resolver_.resolve(netname, ec);
                    lock.lock();
                }
                stat_.resolve_time = stat_.elapse();
                if (ec) {
                    return ec;
                } else if (canceled_) {
                    canceled_ = false;
                    return ec = boost::asio::error::operation_aborted;
                }
                started_ = true;
            }
            ResolverIterator end;
            for (; resolver_iterator_ != end; ++resolver_iterator_) {
                if (!connect_started_) {
                    Endpoint const & e = *resolver_iterator_;
                    {
                        boost::asio::detail::mutex::scoped_lock lock(mutex_);
                        if (canceled_) {
                            ec = boost::asio::error::operation_aborted;
                            canceled_ = false;
                        } else {
                            if (peer.is_open()) {
                                peer.close(ec);
                            }
                            boost::asio::socket_base::non_blocking_io cmd1(non_block_);
#ifndef UNDER_CE
                            boost::asio::socket_base::receive_time_out cmd2(time_out_);
#endif
                            ec || peer.open(endpoint_type(e).protocol(), ec) 
                                || peer.io_control(cmd1, ec) 
#ifndef UNDER_CE
                                || peer.set_option(cmd2, ec)
#endif
                                ;
                        }
                    }
                    if (ec) {
                        break;
                    }
                    LOG_TRACE("[connect] try server, ep: " << e.to_string());
                    start_connect(peer, e, ec);
                } else {
                    ec = boost::asio::error::would_block;
                }
                if (ec == boost::asio::error::would_block) {
                    pool_connect(peer, ec);
                }
                if (ec != boost::asio::error::would_block) {
                    if (!ec) {
                        post_connect(peer, ec);
                    } else {
                        boost::system::error_code ec1;
                        post_connect(peer, ec1);
                    }
                }
                if (!ec || ec == boost::asio::error::would_block || canceled_) {
                    break;
                }
                LOG_DEBUG("[connect] failed, ep: " << 
                    resolver_iterator_->to_string() << ",ec: " << ec.message());
            } // for
            if ((!ec || ec == boost::asio::error::would_block) && canceled_) {
                ec = boost::asio::error::operation_aborted;
            }
            if (ec != boost::asio::error::would_block) {
                stat_.connect_time = stat_.elapse();
                started_ = false;
                canceled_ = false;
            }
            return ec;
        }
コード例 #15
0
ファイル: communication.cpp プロジェクト: Dim-Sal/short
/*
 * Connects to a server
 *  - on success: adds all server related elements
 *  - on failure: retries
 */
void Communication::AddServer(const boost::system::error_code& error,
                              boost::shared_ptr<boost::asio::ip::tcp::socket> soc,
                              boost::asio::ip::tcp::endpoint endpoint,
                              boost::shared_ptr<std::string> server,
                              boost::shared_ptr<std::string> ip,
                              boost::shared_ptr<std::string> port)
{
    // remote host is now connected
    if (!error)
    {
        // lock any "sockets_.size()" usage/modification
        com_mutex_.lock();

        // add a pub, along with all related pub elements
        sockets_.push_back(soc);
        servers_.push_back(server);
        boost::shared_ptr< boost::array<char, 30> > new_buf_ptr(new boost::array<char, 30>);
        new_buf_ptr->assign(0);
        buf_.push_back(new_buf_ptr);
        is_reading_.push_back(false);
        Connection new_server;
        new_server.pub_id = *server;
        new_server.ip = *ip;
        new_server.port = *port;
        connections_.push_back(new_server);

        // report successful connection
        out_mutex_.lock();
        std::cout << "\n[" << boost::this_thread::get_id()
                  << "] >> Connection to " << *server
                  << " at " << endpoint << " succeded \n" << std::endl;
        out_mutex_.unlock();

        // let the read operations begin/continue
        is_pending_add_ = false;
        pending_add_condition_.notify_one();

        // unlock any "sockets_.size()" usage/modification
        com_mutex_.unlock();

        // inform on first connection
        if (sockets_.size() == 1)
        {
            pending_first_condition_->notify_one();
        }
    }

    // remote host is not connected yet
    else if (error.message() == "Connection refused")
    {
        // try again
        usleep(100000);
        soc.reset(new boost::asio::ip::tcp::socket(*io_service_));
        soc->async_connect(endpoint,
                           boost::bind(&Communication::AddServer,
                                       this,
                                       boost::asio::placeholders::error(),
                                       soc,
                                       endpoint,
                                       server,
                                       ip,
                                       port));
    }

    else // report error
    {
        out_mutex_.lock();
        std::cout << "[" << boost::this_thread::get_id()
                  << "] Error: " << error.message() << std::endl;
        out_mutex_.unlock();
    }
}
コード例 #16
0
ファイル: ClientConnection.cpp プロジェクト: vorkostil/vsGame
void ClientConnection::handleWrite( const boost::system::error_code& error )
{
   // if an error occurs, close the connection
	if ( error != 0 )
	{
      std::stringstream stream;
      stream << "ClientConnection (" << technicalId << ") > handleWrite call with error code: " << error.value() << " --> " << error.message();
      AsyncLogger::getInstance()->log( stream.str() );

      connectionManager->closeConnection( shared_from_this() );
	}
}
コード例 #17
0
void handle_error(boost::system::error_code const& error, int expected_error, std::string const& expected_message)
{
	BOOST_CHECK_EQUAL(expected_error, error.value());
	BOOST_CHECK_EQUAL(expected_message, error.message());
}
コード例 #18
0
ファイル: HTTPProxy.cpp プロジェクト: 7histle/i2pd
	void HTTPProxyHandler::SentHTTPFailed(const boost::system::error_code & ecode)
	{
		if (!ecode)
			Terminate();
		else 
		{
			LogPrint (eLogError,"--- HTTP Proxy Closing socket after sending failure because: ", ecode.message ());
			Terminate();
		}
	}
コード例 #19
0
ファイル: RFXComTCP.cpp プロジェクト: htlinux/domoticza
void RFXComTCP::OnError(const boost::system::error_code& error)
{
	_log.Log(LOG_ERROR, "RFXCOM: Error: %s", error.message().c_str());
}
コード例 #20
0
ファイル: smtp.cpp プロジェクト: 0000-bigtree/nscp
		void smtp_client::connection::connected(boost::asio::ip::tcp::resolver::iterator iter, boost::system::error_code ec) {
			if (ec) {
				NSC_LOG_ERROR("smtp failed to connect to " + iter->endpoint().address().to_string() + ": " + ec.message());
				iter++;
				resolved(boost::system::error_code(), iter);
				return;
			}

			NSC_DEBUG_MSG("smtp connected to " + iter->endpoint().address().to_string());
			state = BANNER;
			async_read_response();
		}
コード例 #21
0
ファイル: event_device.cpp プロジェクト: mhx/aird
void event_device::handle_input_event(const boost::system::error_code& e, size_t /*bytes_read*/)
{
   if (e)
   {
      if (m_stopped && e == boost::asio::error::operation_aborted)
      {
         LINFO(m_log, "stopped");
      }
      else
      {
         LERROR(m_log, "async read failed: " << e.message());
      }

      return;
   }

#ifndef NDEBUG
   if (m_log(log_level::DEBUG))
   {
      debug_input_event();
   }
#endif

   switch (m_iev.type)
   {
      case EV_KEY:
         {
            event_code::type code = event_code::KEYBOARD_ACTIVITY;

            switch (m_iev.code)
            {
               case KEY_LEFTCTRL:
                  setmod(M_CTRL, m_iev.value > 0);
                  break;

               case KEY_LEFTSHIFT:
                  setmod(M_SHIFT, m_iev.value > 0);
                  break;

               case KEY_LEFTALT:
                  setmod(M_ALT, m_iev.value > 0);
                  break;

               case KEY_LEFTMETA:
                  setmod(M_META, m_iev.value > 0);
                  break;

               case KEY_BRIGHTNESSUP:
                  code = m_mod == M_CTRL ? event_code::DISPLAY_BRIGHTNESS_UP_SLOW : event_code::DISPLAY_BRIGHTNESS_UP;
                  break;

               case KEY_BRIGHTNESSDOWN:
                  code = m_mod == M_CTRL ? event_code::DISPLAY_BRIGHTNESS_DOWN_SLOW : event_code::DISPLAY_BRIGHTNESS_DOWN;
                  break;

               case KEY_KBDILLUMUP:
                  code = m_mod == M_CTRL ? event_code::KEYBOARD_BRIGHTNESS_UP_SLOW : event_code::KEYBOARD_BRIGHTNESS_UP;
                  break;

               case KEY_KBDILLUMDOWN:
                  code = m_mod == M_CTRL ? event_code::KEYBOARD_BRIGHTNESS_DOWN_SLOW : event_code::KEYBOARD_BRIGHTNESS_DOWN;
                  break;
            }

            m_handler->handle_event(code);
         }

      case EV_SW:
         switch (m_iev.code)
         {
            case SW_LID:
               m_handler->handle_event(m_iev.value > 0 ? event_code::LID_CLOSED : event_code::LID_OPENED);
               break;
         }

      default:
         break;
   }

   read_next_event();
}
コード例 #22
0
void au::SessionTokenTestConnection::HandleContentRead(
        const std::size_t bytes_transferred,
        const boost::system::error_code& ec
    )
{
    if (ec)
    {
        std::cout << "Read content: Got error: " << ec.message() << std::endl;
        request_->Fail(HttpStatusCode::bad_request);
        return;
    }

    auto handler_it = handlers_->find( request_->path );
    if ( handler_it == handlers_->end() )
    {
        std::cout << "Server error: no handler for path: " << request_->path
            << std::endl;
        request_->Fail(HttpStatusCode::not_found);
        return;
    }

    std::istream response_stream(&request_->read_buffer_);

    std::string line;
    if( std::getline(response_stream, line) )
    {
        boost::trim_right(line);
        if ( ! line.empty() )
        {
            request_->post = line;

            std::vector<std::string> post_parts;
            boost::split(
                post_parts,
                line,
                boost::is_any_of("&"));

            for ( const std::string & part : post_parts )
            {
                std::vector<std::string> key_pair;
                boost::split(
                    key_pair,
                    part,
                    boost::is_any_of("="));

                boost::optional<std::string> key = post_parameter::Decode(
                    key_pair[0] );
                if ( ! key )
                {
                    std::cout << "Got invalid POST data." << std::endl;
                    request_->Fail(HttpStatusCode::bad_request);
                    return;
                }

                if (key_pair.size() > 1)
                {
                    boost::optional<std::string> value = post_parameter::Decode(
                        key_pair[1] );
                    if ( ! value )
                    {
                        std::cout << "Got invalid POST data." << std::endl;
                        request_->Fail(HttpStatusCode::bad_request);
                        return;
                    }

                    request_->post_parts[*key] = *value;
                }
                else
                {
                    request_->post_parts[*key] = "";
                }
            }
        }
    }

    // Execute the handler.
    (handler_it->second)(std::move(request_));
}
コード例 #23
0
ファイル: connection.cpp プロジェクト: Daizee/spitfireiii
void connection::handle_read(const boost::system::error_code& e,
							 std::size_t bytes_transferred)
{
	if (!e)
	{
		if (bytes_transferred != size)
		{
			this->client_->m_main->consoleLogger->information(Poco::format("Did not receive proper amount of bytes : rcv: %?d needed: %?d", bytes_transferred, size));
			server.stop(shared_from_this());
			return;
		}
		char * t = buffer_.data();
		if ((*(int8_t*)t != 0x0a) && (*(int8_t*)(t+1) != 0x0b) && (*(int8_t*)(t+2) != 0x01))
		{
			server.consoleLogger->information(Poco::format("Not an AMF3 object - ip:%s", address));
			server.stop(shared_from_this());
			return;
		}
		//printf("uid("XI64")\n", uid);
		// read object size
		if ((size > MAXPACKETSIZE) || (size <= 0))
		{
			//ERROR - object too large - close connection
			server.stop(shared_from_this());
			return;
		}

		//TODO: Decision: have socket read thread handle packets, or push into a queue
		//socket thread (easy, already done)
		// PRO: typically instant response times due to it being processed as it comes in
		// CON: a large request (legit or non) would cause the socket read thread to lag
		// 
		//process thread (complex, ideally better)
		// PRO: can alleviate lag on socket threads and create multiple thread processing queues depending on importance
		// CON: complexity and large requests would typically land in the same thread (causing even more lag for them) unless
		//		made even more complex to have multiple threads for large requests
		//
		//Option 3: Evony style
		// -- create a process thread per x amount of sockets
		// PRO: lag from one client only affects a set amount of players and not the entire server
		// CON: quite complex. is ultimately the process thread option only for x amount of sockets

		// parse packet
		request_.size = size;
		amf3parser * cparser = new amf3parser(buffer_.data());
		try
		{
			request_.object = cparser->ReadNextObject();
			delete cparser;
		}
		catch (...)
		{
			std::cerr << "uncaught handle_request()::amf3parser exception\n";
		}
		request_.conn = this;
		try {
			request_handler_.handle_request(request_, reply_);
		}
		catch (std::exception& e)
		{
			std::cerr << "handle_request() exception: " << e.what() << "\n";
		}
		// 		if (reply_.objects.size() > 0)
		// 		{
		// 			// send reply packets
		// 			try {
		// 				socket_.write_some(reply_.to_buffers());
		// 			}
		// 			catch (std::exception& e)
		// 			{
		// 				std::cerr << "asio::write_some() exception: " << e.what() << "\n";
		// 			}
		// 			reply_.objects.clear();
		// 		}

		boost::asio::async_read(socket_, boost::asio::buffer(buffer_, 4), boost::bind(&connection::handle_read_header, shared_from_this(),
			boost::asio::placeholders::error,
			boost::asio::placeholders::bytes_transferred));
	}
	else if (e != boost::asio::error::operation_aborted)
	{
		server.stop(shared_from_this());
		return;
	}
}
コード例 #24
0
 inline boost::filesystem::path program_location_impl(boost::system::error_code& ec) {
     ec.clear();
     return boost::filesystem::path(getexecname());
 }
コード例 #25
0
ファイル: Player.cpp プロジェクト: D-Pointer/imperium-server
void Player::handlePacket (const boost::system::error_code &error) {
    if ( error ) {
        if ( error == boost::asio::error::eof ) {
            // connection closed
            logDebug << logData( "handlePacket" ) << "connection closed";
        }
        else {
            logError << logData( "handlePacket" ) << "error reading packet data: " << error.message();
        }

        terminate();
        return;
    }

    // create a packet
    SharedPacket packet = std::make_shared<Packet>((Packet::TcpPacketType) m_packetType, m_data, m_dataLength );

    // statistics
    m_statistics->m_lastReceivedTcp = time( 0 );
    m_statistics->m_packetsReceivedTcp++;
    m_statistics->m_bytesReceivedTcp += sizeof( unsigned short ) * 2 + m_dataLength;

    // check the packets that we can receive
    switch ( packet->getType()) {
        case Packet::LoginPacket:
            handleLoginPacket( packet );
            break;

        case Packet::AnnounceGamePacket:
            handleAnnounceGamePacket( packet );
            break;

        case Packet::JoinGamePacket:
            handleJoinGamePacket( packet );
            break;

        case Packet::LeaveGamePacket:
            handleLeaveGamePacket( packet );
            break;

        case Packet::DataPacket:
            handleDataPacket( packet );
            break;

        case Packet::ReadyToStartPacket:
            handleReadyToStartPacket( packet );
            break;

        case Packet::GetResourcePacket:
            handleResourcePacket( packet );
            break;

        case Packet::KeepAlivePacket:
            handleKeepAlivePacket( packet );
            break;

        default:
            logError << logData( "handlePacket" ) << "unknown packet type: " << (int) packet->getType();
            break;
    }

    // the packet manages the data now
    m_data = 0;

    // back to reading the header
    readHeader();
}
コード例 #26
0
ファイル: twitch_irc.cpp プロジェクト: impowski/l33tbot
void twitch_irc::handle_write(const boost::system::error_code &error)
{
    if (error) {
        cerr << error.message() << endl;
    }
}
コード例 #27
0
void Binlog_tcp_driver::handle_net_packet(const boost::system::error_code& err, std::size_t bytes_transferred)
{
  if (err)
  {
    Binary_log_event * ev= create_incident_event(175, err.message().c_str(), m_binlog_offset);
    m_event_queue->push_front(ev);
    return;
  }

  if (bytes_transferred > MAX_PACKAGE_SIZE || bytes_transferred == 0)
  {
    std::ostringstream os;
    os << "Expected byte size to be between 0 and "
       << MAX_PACKAGE_SIZE
       << " number of bytes; got "
       << bytes_transferred
       << " instead.";
    Binary_log_event * ev= create_incident_event(175, os.str().c_str(), m_binlog_offset);
    m_event_queue->push_front(ev);
    return;
  }

  //assert(m_waiting_event != 0);
  //std::cerr << "Committing '"<< bytes_transferred << "' bytes to the event stream." << std::endl;
  m_event_stream_buffer.commit(bytes_transferred);
  /*
    If the event object doesn't have an event length it means that the header
    hasn't been parsed. If the event stream also contains enough bytes
    we make the assumption that the next bytes waiting in the stream is
    the event header and attempt to parse it.
   */
  if (m_waiting_event->event_length == 0 && m_event_stream_buffer.size() >= 19)
  {
    /*
      Copy and remove from the event stream, the remaining bytes might be
      dynamic payload.
     */
    //std::cerr << "Consuming event stream for header. Size before: " << m_event_stream_buffer.size() << std::endl;
    proto_event_packet_header(m_event_stream_buffer, m_waiting_event);
    //std::cerr << " Size after: " << m_event_stream_buffer.size() << std::endl;
  }

  //std::cerr << "Event length: " << m_waiting_event->header()->event_length << " and available payload size is " << m_event_stream_buffer.size()+LOG_EVENT_HEADER_SIZE-1 <<  std::endl;
  if (m_waiting_event->event_length == m_event_stream_buffer.size() + LOG_EVENT_HEADER_SIZE - 1)
  {
    /*
     If the header length equals the size of the payload plus the
     size of the header, the event object is complete.
     Next we need to parse the payload buffer
     */
    std::istream is(&m_event_stream_buffer);
    Binary_log_event * event= parse_event(is, m_waiting_event);

    m_event_stream_buffer.consume(m_event_stream_buffer.size());

    m_event_queue->push_front(event);

    /*
      Note on memory management: The pushed Binary_log_event will be
      deleted in user land.
    */
    delete m_waiting_event;
    m_waiting_event= 0;
  }

  if (!m_shutdown)
    GET_NEXT_PACKET_HEADER;

}
コード例 #28
0
void PushConnection::onError(const boost::system::error_code &ec, Connection::ErrorSource errorSource) {
	std::cout << "PushConnection::onError: " << ec.value() << " " << ec.message() << " source: " << errorSource << std::endl;
	
	//close socket
	close();
}
コード例 #29
0
ファイル: SSLSession.cpp プロジェクト: firememory/Whatway
void SSLSession::handle_handshake(const boost::system::error_code& error)
{
	if (error)
	{
		gFileLog::instance().Log("SSLSession 握手失败, 错误代码:" + boost::lexical_cast<std::string>(error.value()) + ", 错误消息:" + error.message());

		close();
		return;
	}	
	
	read();
}