当前位置: 首页>>代码示例>>C++>>正文


C++ Datagram类代码示例

本文整理汇总了C++中Datagram的典型用法代码示例。如果您正苦于以下问题:C++ Datagram类的具体用法?C++ Datagram怎么用?C++ Datagram使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Datagram类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: throw

//////////////////////////////////////////////////////////////////////
// Datagram 객체로부터 데이타를 읽어서 패킷을 초기화한다.
//////////////////////////////////////////////////////////////////////
void LGIncomingConnectionOK::read (Datagram & iDatagram ) 
	 throw(ProtocolException , Error )
{
	__BEGIN_TRY

	//--------------------------------------------------
	// read Player ID
	//--------------------------------------------------
	BYTE szPlayerID;

	iDatagram.read(szPlayerID);

	if (szPlayerID == 0 )
		throw InvalidProtocolException("szPlayerID == 0");

	if (szPlayerID > 20 )
		throw InvalidProtocolException("too long playerID size");

	iDatagram.read(m_PlayerID , szPlayerID);

	//--------------------------------------------------
	// read TCP Port
	//--------------------------------------------------
	iDatagram.read(m_TCPPort);

	//--------------------------------------------------
	// read Auth Key
	//--------------------------------------------------
	iDatagram.read(m_Key);

	__END_CATCH
}
开发者ID:hillwah,项目名称:darkeden,代码行数:35,代码来源:LGIncomingConnectionOK.cpp

示例2: max

void    Channel::AddHint (Datagram& dgram) {

    tint plan_for = max(TINT_SEC,rtt_avg_*4);

    tint timed_out = NOW - plan_for*2;
    while ( !hint_out_.empty() && hint_out_.front().time < timed_out ) {
        hint_out_size_ -= hint_out_.front().bin.width();
        hint_out_.pop_front();
    }

    int plan_pck = max ( (tint)1, plan_for / dip_avg_ );

    if ( hint_out_size_ < plan_pck ) {

        int diff = plan_pck - hint_out_size_; // TODO: aggregate
        bin64_t hint = transfer().picker().Pick(ack_in_,diff,NOW+plan_for*2);

        if (hint!=bin64_t::NONE) {
            dgram.Push8(SWIFT_HINT);
            dgram.Push32(hint);
            dprintf("%s #%u +hint %s [%lli]\n",tintstr(),id_,hint.str(),hint_out_size_);
            hint_out_.push_back(hint);
            hint_out_size_ += hint.width();
        } else
            dprintf("%s #%u Xhint\n",tintstr(),id_);

    }
}
开发者ID:HexGhost,项目名称:swift,代码行数:28,代码来源:sendrecv.cpp

示例3: throw

//////////////////////////////////////////////////////////////////////
//
// receive datagram from peer
//
// 만약에 이 클래스를 blocking 으로 사용한다면, (즉 select 기반으로)
// 아마도 nReceived 가 0 이하인 경우는 없으리라고 판단된다.
//
//////////////////////////////////////////////////////////////////////
Datagram * DatagramSocket::receive ()
	throw(ConnectException , Error )
{
	__BEGIN_TRY 

	Datagram * pDatagram = NULL;

	SOCKADDR_IN SockAddr;
	uint _szSOCKADDR_IN = szSOCKADDR_IN;

	// 내부 버퍼에다가 복사해둔다.
	int nReceived = SocketAPI::recvfrom_ex(m_SocketID , m_Buffer , DATAGRAM_SOCKET_BUFFER_LEN , 0 , (SOCKADDR*)&SockAddr , &_szSOCKADDR_IN);

	if (nReceived > 0 ) {

		pDatagram = new Datagram();
		pDatagram->setData(m_Buffer , nReceived);
		pDatagram->setAddress(&SockAddr);

	}

	return pDatagram;

	__END_CATCH
}
开发者ID:hillwah,项目名称:darkeden,代码行数:33,代码来源:DatagramSocket.cpp

示例4: throw

//////////////////////////////////////////////////////////////////////
// Datagram 객체로부터 데이타를 읽어서 패킷을 초기화한다.
//////////////////////////////////////////////////////////////////////
void RCSay::read (Datagram & iDatagram ) 
	 throw(ProtocolException , Error )
{
	__BEGIN_TRY

	// Name
	BYTE szName;

	iDatagram.read(szName);

	if (szName == 0 )
		throw InvalidProtocolException("szName == 0");

	if (szName > 20 )
		throw InvalidProtocolException("too long Name length");

	iDatagram.read(m_Name , szName);

	// message
	BYTE szMessage;

	iDatagram.read(szMessage);

	if (szMessage == 0 )
		throw InvalidProtocolException("szMessage == 0");

	if (szMessage > 128 )
		throw InvalidProtocolException("too long message length");

	iDatagram.read(m_Message , szMessage);

	__END_CATCH
}
开发者ID:hillwah,项目名称:darkeden,代码行数:36,代码来源:RCSay.cpp

示例5: lock

void GameDataReceiverThread::run()
{
    const size_t MAX_PACKET_SIZE = 0x1000;

    ScopedLock<Mutex> lock(d->mutex);

    try
    {
        for (;;)
        {
            Datagram dg;
            {
                ReverseScopedLock<Mutex> unlock(d->mutex);

                dg = d->socket->receive(MAX_PACKET_SIZE);
            }

            BufferStream bs(dg.getData());

            framenum_t frameNum = 0;
            FrameData frameData;
            bs >> frameNum >> frameData;

            // Notify
            d->eventLoop->postEvent(new GameDataEvent(frameNum, frameData));
        }
    }
    catch (const Exception& e)
    {
        PERROR << e;
    }
}
开发者ID:ropez,项目名称:pieces,代码行数:32,代码来源:game_data_receiver_thread.cpp

示例6: dprintf

void    Channel::Recv (Datagram& dgram) {
    dprintf("%s #%u recvd %ib\n",tintstr(),id_,dgram.size()+4);
    dgrams_rcvd_++;
    if (last_send_time_ && rtt_avg_==TINT_SEC && dev_avg_==0) {
        rtt_avg_ = NOW - last_send_time_;
        dev_avg_ = rtt_avg_;
        dip_avg_ = rtt_avg_;
        dprintf("%s #%u sendctrl rtt init %lli\n",tintstr(),id_,rtt_avg_);
    }
    bin64_t data = dgram.size() ? bin64_t::NONE : bin64_t::ALL;
    while (dgram.size()) {
        uint8_t type = dgram.Pull8();
        switch (type) {
            case SWIFT_HANDSHAKE: OnHandshake(dgram); break;
            case SWIFT_DATA:      data=OnData(dgram); break;
            case SWIFT_HAVE:      OnHave(dgram); break;
            case SWIFT_ACK:       OnAck(dgram); break;
            case SWIFT_HASH:      OnHash(dgram); break;
            case SWIFT_HINT:      OnHint(dgram); break;
            case SWIFT_PEX_ADD:   OnPex(dgram); break;
            default:
                eprintf("%s #%u ?msg id unknown %i\n",tintstr(),id_,(int)type);
                return;
        }
    }
    last_recv_time_ = NOW;
    sent_since_recv_ = 0;
    Reschedule();
}
开发者ID:HexGhost,项目名称:swift,代码行数:29,代码来源:sendrecv.cpp

示例7: printf

bool CanonDriver::requestCurrentPos()
{
	Datagram dgm;
	dgm.reset();
	dgm.setId(0x33);
	dgm.setStatus(0x8000);

	cm.addToReceptionField(0x33);
	if (!cm.send(dgm)) {
		if (verbose) {
			printf("%s: Can't send datagram: ",__FUNCTION__);
			dgm.print(stdout);
			printf("\n");
		}
		goto cleanup;
	}

	if (!cm.wait(0x33,dgm)) goto cleanup;
	cm.removeFromReceptionField(0x33);
	return interpreteDatagram33(dgm);

cleanup:
	if (verbose)
		printf("requestCurrentPos failed\n");
	cm.removeFromReceptionField(0x33);
	return false;
}
开发者ID:OspreyX,项目名称:ros-drivers,代码行数:27,代码来源:CanonDriver.cpp

示例8: file

void    Channel::AddPeakHashes (Datagram& dgram) {
    for(int i=0; i<file().peak_count(); i++) {
        bin64_t peak = file().peak(i);
        dgram.Push8(SWIFT_HASH);
        dgram.Push32((uint32_t)peak);
        dgram.PushHash(file().peak_hash(i));
        dprintf("%s #%u +phash %s\n",tintstr(),id_,peak.str());
    }
}
开发者ID:HexGhost,项目名称:swift,代码行数:9,代码来源:sendrecv.cpp

示例9: eprintf

void    Channel::OnAck (Datagram& dgram) {
    bin64_t ackd_pos = dgram.Pull32();
    tint peer_time = dgram.Pull64(); // FIXME 32
    // FIXME FIXME: wrap around here
    if (ackd_pos==bin64_t::NONE)
        return; // likely, brocken packet / insufficient hashes
    if (file().size() && ackd_pos.base_offset()>=file().packet_size()) {
        eprintf("invalid ack: %s\n",ackd_pos.str());
        return;
    }
    ack_in_.set(ackd_pos);
    int di = 0, ri = 0;
    // find an entry for the send (data out) event
    while (  di<data_out_.size() && ( data_out_[di]==tintbin() ||
           !data_out_[di].bin.within(ackd_pos) )  )
        di++;
    // FUTURE: delayed acks
    // rule out retransmits
    while (  ri<data_out_tmo_.size() && !data_out_tmo_[ri].bin.within(ackd_pos) )
        ri++;
    dprintf("%s #%u %cack %s %lli\n",tintstr(),id_,
            di==data_out_.size()?'?':'-',ackd_pos.str(),peer_time);
    if (di!=data_out_.size() && ri==data_out_tmo_.size()) { // not a retransmit
            // round trip time calculations
        tint rtt = NOW-data_out_[di].time;
        rtt_avg_ = (rtt_avg_*7 + rtt) >> 3;
        dev_avg_ = ( dev_avg_*3 + abs(rtt-rtt_avg_) ) >> 2;
        assert(data_out_[di].time!=TINT_NEVER);
            // one-way delay calculations
        tint owd = peer_time - data_out_[di].time;
        owd_cur_bin_ = 0;//(owd_cur_bin_+1) & 3;
        owd_current_[owd_cur_bin_] = owd;
        if ( owd_min_bin_start_+TINT_SEC*30 < NOW ) {
            owd_min_bin_start_ = NOW;
            owd_min_bin_ = (owd_min_bin_+1) & 3;
            owd_min_bins_[owd_min_bin_] = TINT_NEVER;
        }
        if (owd_min_bins_[owd_min_bin_]>owd)
            owd_min_bins_[owd_min_bin_] = owd;
        dprintf("%s #%u sendctrl rtt %lli dev %lli based on %s\n",
                tintstr(),id_,rtt_avg_,dev_avg_,data_out_[di].bin.str());
        ack_rcvd_recent_++;
        // early loss detection by packet reordering
        for (int re=0; re<di-MAX_REORDERING; re++) {
            if (data_out_[re]==tintbin())
                continue;
            ack_not_rcvd_recent_++;
            data_out_tmo_.push_back(data_out_[re].bin);
            dprintf("%s #%u Rdata %s\n",tintstr(),id_,data_out_.front().bin.str());
            data_out_cap_ = bin64_t::ALL;
            data_out_[re] = tintbin();
        }
    }
开发者ID:HexGhost,项目名称:swift,代码行数:53,代码来源:sendrecv.cpp

示例10: getFocusMode

bool CanonDriver::getFocusMode(FocusMode * fm, ManualFocusMode * mfm)
{
	Datagram dgm;
	if (!sendRequestAndWait(0x40,0x8000,dgm))
		return false;
	*fm = (FocusMode)(dgm.bdata()[0]);
	if (*fm == FMManual) {
		if (!sendRequestAndWait(0x43,0x8000,dgm))
			return false;
		*mfm = (ManualFocusMode)(dgm.bdata()[0]);
	}
	return true;
}
开发者ID:OspreyX,项目名称:ros-drivers,代码行数:13,代码来源:CanonDriver.cpp

示例11: readPacket

Datagram* IpRouter::readPacket() {
    // If the file stream is at the end of the file, all packets have been read. Return NULL.
    if(packetsFS.peek() == EOF) {
        packetsFS.close();
        return NULL;
    }

    // Create a packet on the Heap so it can exist longer than the scope of this function
    Datagram* packet = new Datagram;

    // Read packet data into object
    packet->read(packetsFS);

    return packet;
}
开发者ID:jamirvin,项目名称:IP_Forward,代码行数:15,代码来源:iprouter.cpp

示例12: getSpeeds

bool CanonDriver::getSpeeds(unsigned short * pan, 
		unsigned short * tilt, unsigned short * zoom)
{
	Datagram dgm;
	if (!sendRequestAndWait(0x3B,0x8000,dgm))
		return false;
	const unsigned char * data = dgm.bdata();
	*pan = data[0];
	*pan = (*pan << 8) | data[1];
	*tilt = data[2];
	*tilt = (*tilt << 8) | data[3];
	*zoom = data[4];
	*zoom = (*zoom << 8) | data[5];
	return true;
}
开发者ID:OspreyX,项目名称:ros-drivers,代码行数:15,代码来源:CanonDriver.cpp

示例13: log_event

void Client::log_event(const std::list<std::string> &event)
{
	Datagram dg;

	std::stringstream ss;
	ss << "Client:" << m_allocated_channel;
	dg.add_string(ss.str());

	for(auto it = event.begin(); it != event.end(); ++it)
	{
		dg.add_string(*it);
	}

	g_eventsender.send(dg);
}
开发者ID:shadowcoder,项目名称:Astron,代码行数:15,代码来源:Client.cpp

示例14: send_down

int gcomm::PC::handle_down(Datagram& wb, const ProtoDownMeta& dm)
{
    if (wb.len() == 0)
    {
        gu_throw_error(EMSGSIZE);
    }
    return send_down(wb, dm);
}
开发者ID:cyclefusion,项目名称:galera,代码行数:8,代码来源:pc.cpp

示例15: getAutoExposure

bool CanonDriver::getAutoExposure(bool * autoexp, AutoExposureMode * aem)
{
	Datagram dgm;
	if (!sendRequestAndWait(0x82,0x8000,dgm))
		return false;
	//dgm.print();
	*autoexp = (dgm.bdata()[0] == 0x00);
	if (!*autoexp) {
		*aem = AXPundef;
		return true;
	}
	if (!sendRequestAndWait(0x87,0x8000,dgm))
		return false;
	unsigned short us = dgm.bdata()[0];
	us = (us << 8) | dgm.bdata()[1];
	*aem = (AutoExposureMode)(us);
	//dgm.print();
	return true;
}
开发者ID:OspreyX,项目名称:ros-drivers,代码行数:19,代码来源:CanonDriver.cpp


注:本文中的Datagram类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。