//发送一个握手失败的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);
}
Exemple #2
0
int main(int argc, char** argv)
{
    BinStream b;
    string output_file;
    int argoffs = 0;

    // Manage options
    for (int i = 1; i < argc; ++i)
    {
        if (argv[i][0] == '-')
        {
            argoffs++;
            // set verbose mode with -v
            if (argv[i][1] == 'v')
            {
                b.set_verbosity(true);
            }
            // show help and exit with -h
            else if (argv[i][1] == 'h')
            {
                usage(argv[0]);
                return 0;
            }
            // get output file name with -o FILENAME
            else if (argv[i][1] == 'o')
            {
                i++;
                argoffs++;
                output_file = argv[i];
            }
            else
            {
                cerr << "WARNING: Unexpected option '" << argv[i] << "'" << endl;
            }
        }
    }
    argc -= argoffs;

    if ((argc > 1) && (argc <= 3))
    {
        // read input data from file
        ifstream f(argv[argoffs + 1]);
        b << f;
        if ((argc == 3) || (!output_file.empty()))
        {
            // write output data to file
            if (output_file.empty())
            {
                output_file = argv[argoffs + 2];
            }
            ofstream t(output_file.c_str());
            b >> t;
            t.close();
        }
        else
        {
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;
}
Exemple #4
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;
}
Exemple #5
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);
}