示例#1
0
void udp_port::on_recv(const error_code& error, size_t size)
{
	if (error == boost::asio::error::message_size) {
		LOG_DEBUG("UDP received oversized message");
		start_recv();
	}
	if (error) {
		FATAL("UDP fatal error: %s", error.message().c_str());
	}
	for(auto proto : m_protocols) {
		if (proto(m_endpoint, m_buffer, size)) {
			break;
		}
	}
	start_recv();
}
示例#2
0
int32_t bind2engine(ENGINE e,struct connection *c,
    CCB_PROCESS_PKT cb_process_packet,CCB_DISCONNECT cb_disconnect)
{
    c->cb_process_packet = cb_process_packet;
    c->cb_disconnect = cb_disconnect;
	start_recv(c);
	return Bind2Engine(e,c->socket,IoFinish,NULL);
}
示例#3
0
 void start_all( )
 {
     std::lock_guard<std::mutex> l(points_lock_);
     for( auto &p: points_ ) {
         LOGINF << "Starting point: " << p.first;
         start_recv( p.second );
     }
 }
示例#4
0
  void AsyncConnection::handle_buffer()
  {
    switch (state_)
    {
    case kReadFrameSize:
      if (bytes_recv_ >= sizeof(uint32_t))
      {
        //got the frame length
        get_frame_size();

        if (frame_size_ >= kMaxFrameSize || frame_size_ == 0)
        {
          GlobalOutput.printf("illegal frame size: %u", frame_size_);
          return;
        }

        //fall through to "case kReadFrame"
        //the buffer may contains a complete frame, or a partial frame
        state_ = kReadFrame;
      }
      else
      {
        //continue to read
        start_recv(false);
        break;
      }

    case kReadFrame:
      if (bytes_recv_ >= frame_size_+sizeof(uint32_t))
      {
        //got a complete frame, handle it
        input_buffer_->resetBuffer(&recv_buffer_[0], frame_size_+sizeof(uint32_t));
        output_buffer_->resetBuffer();
        on_handle_frame();
      }
      else
      {
        //continue to read
        start_recv(false);
      }
      break;
    }
  }
示例#5
0
void QNetTcpServer::server_start(int sk)
{
  socket = sk;
  quit = 0;
  start_send();
  start_treasmit();
  start_recv();
  //usleep(100000);

}
void resolution_service::receive(const boost::system::error_code& error, std::size_t) {
	if(error) return;
	std::cout << "Receiving UDP data" << std::endl;
	dvsp_packet in(m_recv);
	auto inbound_addr = m_remote_ep.address();
	auto out = m_proto.process_packet(in, inbound_addr);
	auto out_shr = std::shared_ptr<char>(out->serialise());
	m_socket.async_send_to(
		boost::asio::buffer(out_shr.get(), out->size()),
		m_remote_ep,
		[this](const berror&, std::size_t) { 
	});
	start_recv();
}
示例#7
0
        void handle_receive( const boost::system::error_code& error,
                             size_t bytes_recvd,
                             point_wptr info )
        {
            if( error ) {
                LOGERR << "Recv error: " << error.message( )
                       << " (code: " << error.value() << ")";
                return;
            }

            auto lck = info.lock( );
            if( lck ) {
                LOGDBG << "Recv request from "
                       << lck->from.address( ).to_string( )
                       << ":" << lck->from.port( )
                          ;
                ///
                req_res( *lck, bytes_recvd );
                ///
                start_recv( lck );
            }
        }
示例#8
0
  void AsyncConnection::on_handle_write(
    const boost::system::error_code& ec, size_t bytes_transferred)
  {
    if (ec)
      return;

    assert(bytes_recv_ >= frame_size_+sizeof(uint32_t));
    if (bytes_recv_ == frame_size_+sizeof(uint32_t))
    {
      //buffer is empty, restart
      start_recv(true);
    }
    else
    {
      //consume the previous frame buffer, and handle the buffer remained
      memcpy(&recv_buffer_[0], &recv_buffer_[frame_size_+sizeof(uint32_t)],
        bytes_recv_-frame_size_-sizeof(uint32_t));
      bytes_recv_ -= (frame_size_+sizeof(uint32_t));
      frame_size_ = 0;
      state_ = kReadFrameSize;
      handle_buffer();
    }
  }
示例#9
0
udp_port::udp_port(io_service& ios, uint16_t port)
	: m_socket(ios, udp_endpoint(boost::asio::ip::udp::v4(), port))
{
	start_recv();
}
resolution_service::resolution_service(netspace_ios& ios, netspace_table& nstable, metaspace_gsn& msgsn)
	: m_socket(ios, nsudp::endpoint(nsudp::v4(), GSN_SERVICE_PORT))
	, m_nstable(nstable)
	, m_msgsn(msgsn)
	, m_proto(m_nstable, m_msgsn)
{ start_recv(); }