Пример #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;
}
Пример #2
0
//发送一个握手失败的SYN2
void RUDPObject::send_syn2(uint32_t remote_rudp_id, uint8_t result, uint16_t check_sum, const Inet_Addr& remote_addr, IRUDPAdapter* adapter)
{
	if(adapter == NULL)
		return ;

	RUDPHeadPacket head;
	head.msg_id_ = RUDP_SYN2;
	head.remote_rudp_id_ = remote_rudp_id;
	head.check_sum_ = check_sum;

	RUDPSyn2Packet syn2;
	syn2.version_ = RUDP_VERSION;
	syn2.local_rudp_id_ = 0;
	syn2.local_ts_ = CBaseTimeValue::get_time_value().msec();
	syn2.remote_ts_ = syn2.local_ts_;
	syn2.syn2_result_ = result;
	syn2.max_segment_size_ = MAX_SEGMENT_SIZE;
	syn2.start_seq_ = 0;

	BinStream strm;
	strm.rewind(true);
	strm << adapter->get_title() << head << syn2;

	adapter->send(strm, remote_addr);
}