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


C++ PacketQueue类代码示例

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


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

示例1: processAck

void ReliabilitySystem::processAck( quint32 ack
									, quint32 ack_bits
									, PacketQueue & pending_ack_queue
									, PacketQueue & acked_queue
									, QVector<quint32> & acked
									, quint32 & acked_packets
									, float & rtt
									, quint32 max_sequence)
{
	if ( pending_ack_queue.empty() ){
		return;
	}

	PacketQueue::iterator itor = pending_ack_queue.begin();
	while ( itor != pending_ack_queue.end() ) {
		bool wasAcked = false;

		if ( itor->sequence == ack ) {
			wasAcked = true;
		}
		else if ( !sequenceIsMoreRecent( itor->sequence, ack, max_sequence ) ) {
			qint32 bit_index = bitIndexForSequence( itor->sequence, ack, max_sequence );
			if ( bit_index <= 31 ){
				wasAcked = ( ack_bits >> bit_index ) & 1;
			}
		}
开发者ID:mrdeveloperdude,项目名称:OctoMY,代码行数:26,代码来源:ReliabilitySystem.cpp

示例2: process_ack

void ReliabilitySystem::process_ack(unsigned int ack, unsigned int ack_bits,
							PacketQueue & pending_ack_queue, PacketQueue & acked_queue,
							std::vector<unsigned int> & acks, unsigned int & acked_packets,
							float & rtt, unsigned int max_sequence)
{
	if (pending_ack_queue.empty())
		return;

	PacketQueue::iterator itor = pending_ack_queue.begin();
	while (itor != pending_ack_queue.end()) {
		bool acked = false;

		if (itor->sequence == ack) {
			acked = true;
		} else if (!sequence_more_recent(itor->sequence, ack, max_sequence)) {
			int bit_index = bit_index_for_sequence(itor->sequence, ack, max_sequence);
			if (bit_index <= 31)
				acked = (ack_bits >> bit_index) & 1;
		}

		if (acked) {
			rtt += (itor->time - rtt) * 0.1f;

			acked_queue.insert_sorted(*itor, max_sequence);
			acks.push_back(itor->sequence);
			acked_packets++;
			itor = pending_ack_queue.erase(itor);
		} else {
			++itor;
		}
	}
开发者ID:SpexGuy,项目名称:OnlineBoardGame,代码行数:31,代码来源:ReliabilitySystem.cpp

示例3: PacketQueue

int
FIFONode::send(Packet* packet)
{
    Address 	 	nhop;
    PacketQueue* 	queue;
    QueueMapIterator	qiter;

    // Compute the nexthop
    nhop = topology->nexthop(address(), packet->destination);

    // Find the queue
    qiter = queue_map.find(nhop);
    if (qiter == queue_map.end()) { // An entry doesn't exist
        queue = new PacketQueue(max_queue_size, address(), nhop);
        QueueMapPair np(nhop, queue);
        queue_map.insert(np);
    } else {
        queue = (*qiter).second;
    }
    
    // Check if there is space
    if (queue->enq(packet)) {
        TRACE(TRL2, "Enqueued at %d packet (src %d, dst %d, id %d)\n",
              address(), packet->source, packet->destination, packet->id);
        send_it(nhop);
        return 1;
    }

    TRACE(TRL2, "Queue full at %d, dropped packet (src %d, dst %d, id %d)\n",
          address(), packet->source, packet->destination, packet->id);
    delete packet;
    return 0;
}
开发者ID:iampradiptaghosh,项目名称:chotu,代码行数:33,代码来源:FIFONode.cpp

示例4: main

int main(int argc, char ** argv)
{
	Connection con;	

	std::mutex zbSenderConditionVariableMutex;
	std::condition_variable zbSenderConditionVariable;
	PacketQueue zbSendQueue;
	ZBSender * zbSender = new ZBSender(con.openPort(atoi(argv[1]), 9600), &zbSenderConditionVariableMutex, &zbSenderConditionVariable, &zbSendQueue);

	
	boost::thread * zbSenderThread = new boost::thread(boost::ref(*zbSender));



	std::vector<unsigned char> zigbeeAddress64bit{0X00, 0X13, 0XA2, 0X00, 0X40, 0X69, 0X73, 0X77};
	std::vector<SensorType> sensors{TEMP, PRES, BAT};

	for(int i = 0; i < 20; ++i)
	{
		LibelAddNodePacket * libelAddNodePacket = new LibelAddNodePacket(zigbeeAddress64bit, sensors);	 	
		zbSendQueue.addPacket(dynamic_cast<Packet *> (libelAddNodePacket));
		zbSenderConditionVariableMutex.lock();
		zbSenderConditionVariable.notify_all();
		zbSenderConditionVariableMutex.unlock();
		std::cout << "packet sent" << std::endl;
		sleep(5);

	}
	zbSenderThread->join();
	delete zbSender;
	delete zbSenderThread;
	return 0;
}
开发者ID:macntouch,项目名称:Qt_ZigbeeWSN,代码行数:33,代码来源:sendAddNode.cpp

示例5: process_ack

		void ReliabilitySystem::process_ack( unsigned int ack, unsigned int ack_bits, 
								 PacketQueue & pending_ack_queue, PacketQueue & acked_queue, 
								 std::vector<unsigned int> & acks, unsigned int & acked_packets, 
								 float & rtt, unsigned int max_sequence )
		{
			if ( pending_ack_queue.empty() ) {
				return;
			}
				
			PacketQueue::iterator itor = pending_ack_queue.begin();
			while ( itor != pending_ack_queue.end() )
			{
				bool acked = false;
				
				if ( itor->sequence == ack )
				{
					acked = true;
				}
				else if ( !sequence_more_recent( itor->sequence, ack, max_sequence ) )
				{
					int bit_index = bit_index_for_sequence( itor->sequence, ack, max_sequence );
					if ( bit_index <= 31 ) { 
						acked = ( ack_bits >> bit_index ) & 1;
					}
				}
开发者ID:ashleygwinnell,项目名称:ark2d,代码行数:25,代码来源:ReliabilitySystem.cpp

示例6: TEST_F

TEST_F( PacketTest, SendPacket ) {
   const DestinationID kFirstChannel  = 5;
   const DestinationID kSecondChannel = 10;

   class TestPacketSubscriber : public PacketSubscriber {
   public:

      bool sendPacket( DestinationID destination_id )
      {
         NetAppPacket* packet_ptr = new NetAppPacket( destination_id, 100 );
         bool success = sendTo( destination_id, packet_ptr );
         if ( success == false )
         {
            delete packet_ptr;
         }
         return success;
      }

      bool put( DestinationID destination_id, const void* data_ptr, ui32 length )
      {
         return true;
      }
   };

   PacketQueue queue;
   PacketRouter router(&queue);
   TestPacketSubscriber subscriber;

   EXPECT_EQ( -1, router.count( kFirstChannel ) );
   EXPECT_EQ( -1, router.count( kSecondChannel ) );

   // Test registeration
   EXPECT_FALSE( subscriber.isSubscribed() );
   EXPECT_EQ( true, router.subscribe( kFirstChannel, &subscriber, kSubscriberModeReadWrite ) );
   EXPECT_EQ( true, router.subscribe( kSecondChannel, &subscriber, kSubscriberModeReadOnly ) );
   EXPECT_EQ( true, subscriber.isSubscribed() );
   EXPECT_EQ( 1, router.count( kFirstChannel ) );
   EXPECT_EQ( 1, router.count( kSecondChannel ) );

   // Send a packet on the first channel.
   EXPECT_EQ( true, subscriber.sendPacket( kFirstChannel ) );
   PacketContainer* container_ptr = queue.pop();
   EXPECT_TRUE( ( container_ptr != NULL ) );
   EXPECT_EQ( kFirstChannel, container_ptr->destination_id_ );
   EXPECT_EQ( 108, container_ptr->packet_ptr_->allocatedSize() );
   // delete container_ptr->packet_ptr_;
   // delete container_ptr;


   // Test unregisteration
   EXPECT_EQ( true, router.unsubscribe( kFirstChannel, &subscriber ) );
   EXPECT_EQ( true, router.unsubscribe( kSecondChannel, &subscriber ) );
   EXPECT_FALSE( subscriber.isSubscribed() );

   EXPECT_EQ( 0, router.count( kFirstChannel ) );
   EXPECT_EQ( 0, router.count( kSecondChannel ) );
}
开发者ID:rgmann,项目名称:coral,代码行数:57,代码来源:packet_router_test.cpp

示例7: generate_ack_bits

unsigned int ReliabilitySystem::generate_ack_bits(unsigned int ack, const PacketQueue & received_queue, unsigned int max_sequence) {
	unsigned int ack_bits = 0;
	for (PacketQueue::const_iterator itor = received_queue.begin(); itor != received_queue.end(); itor++) {
		if (itor->sequence == ack || sequence_more_recent(itor->sequence, ack, max_sequence))
			break;
		int bit_index = bit_index_for_sequence(itor->sequence, ack, max_sequence);
		if (bit_index <= 31)
			ack_bits |= 1 << bit_index;
	}
	return ack_bits;
}
开发者ID:SpexGuy,项目名称:OnlineBoardGame,代码行数:11,代码来源:ReliabilitySystem.cpp

示例8: get_packets

casr::State::PacketQueue casr::State::get_current_packets(int process_id1, int process_id2)
{
	PacketQueue &pq = get_packets(process_id1, process_id2);
	PacketQueue result;
	for (size_t t = 0; t < pq.size(); t++) {
		if (global_time >= pq[t].start_time) {
			result.push_back(pq[t]);
		}
	}
	return result;
}
开发者ID:DiPi22,项目名称:kaira,代码行数:11,代码来源:state.cpp

示例9: generateAckBits

quint32 ReliabilitySystem::generateAckBits( quint32 ack, const PacketQueue & received_queue, quint32 max_sequence ) {
	quint32 ack_bits = 0;
	for ( PacketQueue::const_iterator itor = received_queue.begin(); itor != received_queue.end(); itor++ ) {
		if ( itor->sequence == ack || sequenceIsMoreRecent( itor->sequence, ack, max_sequence ) ){
			break;
		}
		qint32 bit_index = bitIndexForSequence( itor->sequence, ack, max_sequence );
		if ( bit_index <= 31 ){
			ack_bits |= 1 << bit_index;
		}
	}
	return ack_bits;
}
开发者ID:mrdeveloperdude,项目名称:OctoMY,代码行数:13,代码来源:ReliabilitySystem.cpp

示例10: TEST_F

TEST_F( RelayTest, CollectPacket ) {

   PacketQueue queue;
   PacketRouter router(&queue);
   TestPacketSubscriber subscriber_1;
   TestPacketSubscriber subscriber_2;
   TestPacketRelay relay;

   EXPECT_EQ( -1, router.count( kFirstChannel ) );
   EXPECT_EQ( -1, router.count( kSecondChannel ) );

   // Test registeration
   EXPECT_FALSE( subscriber_1.isSubscribed() );
   EXPECT_FALSE( subscriber_2.isSubscribed() );

   EXPECT_EQ( true, router.subscribe( RELAY_PIPE, &relay, kSubscriberModeReadWrite ) );
   EXPECT_EQ( true, relay.subscribe( kFirstChannel, &subscriber_1, kSubscriberModeReadWrite ) );
   EXPECT_EQ( true, relay.subscribe( kSecondChannel, &subscriber_2, kSubscriberModeReadWrite ) );
   EXPECT_EQ( true, subscriber_1.isSubscribed() );
   EXPECT_EQ( true, subscriber_2.isSubscribed() );
   EXPECT_EQ( 1, relay.count( kFirstChannel ) );
   EXPECT_EQ( 1, relay.count( kSecondChannel ) );

   // Route some packets.
   EXPECT_EQ( true, subscriber_1.sendPacket( kFirstChannel ) );
   EXPECT_EQ( true, subscriber_2.sendPacket( kSecondChannel ) );

   PacketContainer* container_ptr = queue.pop();
   EXPECT_TRUE( ( container_ptr != NULL ) );
   EXPECT_EQ( RELAY_PIPE, container_ptr->destination_id_ );
   NetAppPacket::Data* header_ptr = (NetAppPacket::Data*)container_ptr->packet_ptr_->basePtr();
   EXPECT_EQ( kFirstChannel, (DestinationID)header_ptr->type );

   container_ptr = queue.pop();
   EXPECT_TRUE( ( container_ptr != NULL ) );
   EXPECT_EQ( RELAY_PIPE, container_ptr->destination_id_ );
   header_ptr = (NetAppPacket::Data*)container_ptr->packet_ptr_->basePtr();
   EXPECT_EQ( kSecondChannel, (DestinationID)header_ptr->type );

   // Test unregisteration
   EXPECT_EQ( true, relay.unsubscribe( kFirstChannel, &subscriber_1 ) );
   EXPECT_EQ( true, relay.unsubscribe( kSecondChannel, &subscriber_2 ) );
   EXPECT_EQ( true, router.unsubscribe( RELAY_PIPE, &relay ) );
   EXPECT_FALSE( subscriber_1.isSubscribed() );
   EXPECT_FALSE( subscriber_2.isSubscribed() );
   EXPECT_EQ( 0, relay.count( kFirstChannel ) );
   EXPECT_EQ( 0, relay.count( kSecondChannel ) );
   EXPECT_EQ( 0, router.count( RELAY_PIPE ) );
}
开发者ID:rgmann,项目名称:coral,代码行数:49,代码来源:packet_relay_test.cpp

示例11: pushQueue

// pushQueue
void PacketQueueThread::pushQueue(PacketQueue &packetQueue, int maxQueueLen) {
    // 是停止就不允许放了
    if (_stop) {
        return;
    }

    // 是否要限制push长度
    if (maxQueueLen>0 && _queue._size >= maxQueueLen) {
        _pushcond.lock();
        _waiting = true;
        while (_stop == false && _queue.size() >= maxQueueLen) {
            _pushcond.wait(1000);
        }
        _waiting = false;
        _pushcond.unlock();
        if (_stop) {
            return;
        }
    }

    // 加锁写入队列
    _cond.lock();
    packetQueue.moveTo(&_queue);
    _cond.unlock();
    _cond.signal();
}
开发者ID:CCoder123,项目名称:pproj,代码行数:27,代码来源:packetqueuethread.cpp

示例12: ReadRTPFunc

static int ReadRTPFunc(void *opaque, uint8_t *buf, int buf_size) {
    //printf("WIN 2!!!!!! %d\n", buf_size);
    FLOWPacket pkt;
    int written_size = 0;
    PacketQueue* q = (PacketQueue*)opaque;
    int ret = q->get(&pkt);
    int i = 0;
    //printf("Queue Size %d %d\n", q->m_PlayoutPackets->size(), pkt.m_SeqNum);
    if ( (ret != 1) && (written_size + pkt.m_Size < 1473)) {
        i++;
        memcpy(buf+written_size, pkt.m_Data, pkt.m_Size);
        written_size += pkt.m_Size;
        //delete pkt.m_Data;
        //ret = q->get(&pkt);
    }
    
    //printf("Written !!!!!! %d %d %d\n", written_size, buf_size, ret);
    if ( written_size == 0 ) {
        inputExhausted = true;
    }
    return written_size;
}
开发者ID:ViNi89,项目名称:FLOW,代码行数:22,代码来源:fwInputHandler.cpp

示例13: ASSERT

void
FIFONode::send_it(Address nhop)
{
    PacketQueue*	queue;
    QueueMapIterator	qiter;
    Packet*		pkt;

    qiter = queue_map.find(nhop);
    ASSERT(qiter != queue_map.end());
    queue = (*qiter).second;

    if (queue->pending_send) {
        return;
    }

    pkt = queue->deq();
    if (pkt) {
        TRACE(TRL2, "Forwarding at %d to nexthop %d packet (src %d, dst %d, id %d)\n",
              address(), nhop, pkt->source, pkt->destination, pkt->id);
        Node::send(pkt, nhop);
        queue->pending_send = 1;
    }
    return;
}
开发者ID:iampradiptaghosh,项目名称:chotu,代码行数:24,代码来源:FIFONode.cpp

示例14: dvbsub_ass_clear

void dvbsub_ass_clear(void)
{
	OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(ass_mutex);

	while(ass_queue.size()) {
		ass_data *a = (ass_data *) ass_queue.pop();
		if (a) {
			avsubtitle_free(&a->sub);
			delete a;
		}
	}
	while(!sem_trywait(&ass_sem));

	ass_track = NULL;
	for(std::map<int,ASS_Track*>::iterator it = ass_map.begin(); it != ass_map.end(); ++it)
		ass_free_track(it->second);
	ass_map.clear();
	if (ass_renderer) {
		ass_renderer_done(ass_renderer);
		ass_renderer = NULL;
	}
	if (ass_library) {
		ass_library_done(ass_library);
		ass_library = NULL;
	}
	clear_queue();
}
开发者ID:j00zek,项目名称:j00zeks-neutrino-mp-cst-next,代码行数:27,代码来源:dvbsub.cpp

示例15: Inject

void Inject() {
	list<InjectReqMsg> packets = packet_queue.DeQueue(cycle);
	list<InjectReqMsg>::iterator it;

	for(it = packets.begin(); it != packets.end(); ++it) {
		sendPacket(*it);
	}

	packet_queue.CleanUp(cycle);
}
开发者ID:nicmcd,项目名称:ee382c_final_project,代码行数:10,代码来源:TrafficGenerator.cpp


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