Exemplo n.º 1
0
int32_t CoreUDPHandler::send(BinStream& bin_strm, const Inet_Addr& remote_addr)
{
    int32_t rc = sock_dgram_.send(bin_strm.get_rptr(), bin_strm.data_size(), remote_addr);
    if(rc < 0)
    {
        if(XEAGAIN == error_no() || XEINPROGRESS == error_no()) //插入一个写事件,防止SOCKET异常
        {
            CORE_WARNING("core udp send EAGAIN");
            REACTOR_INSTANCE()->register_handler(this, MASK_WRITE);

            bin_strm.rewind(true);
            return 0;
        }
        else
        {
            bin_strm.rewind(true);
            CORE_FATAL("core udp send failed, remote addr = " << remote_addr);
            return -1;
        }

        bin_strm.rewind(true);
    }

    THROTTLER()->add_udp_packet(bin_strm.data_size(), true);

    bin_strm.rewind(true);
    return rc;
}
Exemplo n.º 2
0
void RUDPSocket::process_data(BinStream& strm, const Inet_Addr& remote_addr)
{
    if(state_ != RUDP_CONNECTED)
    {
        RUDP_WARNING("process data, state != RUDP_CONNECTED");
        return ;
    }

    RUDPData data;
    strm >> data;

    ccc_.on_ack(data.ack_seq_id_);
    send_buffer_.on_ack(data.ack_seq_id_);

    uint32_t data_size = 0;
    strm >> data_size;

    recv_buffer_.on_data(data.cur_seq_id_, (const uint8_t *)strm.get_rptr(), data_size);
}
Exemplo n.º 3
0
int32_t RecvUDPHandler::send(BinStream& bin_strm, const Inet_Addr& remote_addr)
{
	//if(rand() % 50 == 1)
	//	return 0;

	int32_t rc = sock_dgram_.send(bin_strm.get_rptr(), bin_strm.data_size(), remote_addr);
	if(rc < 0)
	{
		if(XEAGAIN == error_no() || XEINPROGRESS == error_no()) //插入一个写事件,防止SOCKET异常
		{
			REACTOR_INSTANCE()->register_handler(this, MASK_WRITE);

			return 0;
		}
		else
		{
			return -1;
		}
	}

	return rc;
}