• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ Packet函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Packet

void QuestsPacket::questFinish(Player* player, vector <Player*> players,short questid, int npcid, short nextquest, __int64 time){
	Packet packet = Packet();
	packet.addHeader(0x32);
	packet.addByte(1);
	packet.addShort(questid);
	packet.addByte(2);
	packet.addInt64(time);
	packet.packetSend(player);
	packet = Packet();
	packet.addHeader(0x6D);
	packet.addByte(6);
	packet.addShort(questid); 
	packet.addInt(npcid); 
	packet.addShort(nextquest); 
	packet.packetSend(player);
	packet = Packet();
	packet.addHeader(0x68);
	packet.addByte(9);
	packet.packetSend(player);
	packet = Packet();
	packet.addHeader(0x86);
	packet.addInt(player->getPlayerid());
	packet.addByte(9);
	packet.sendTo(player, players, 0);
}
开发者ID:Dephon,项目名称:MapleStory_tms,代码行数:25,代码来源:QuestsPacket.cpp


示例2: firm_str

bool YModem::SendFile(const std::string &path, YModem::SPort &out) {
  if (path.size() == 0 ||
      not out.is_open())
    return false;
  std::fstream firm_str(path.c_str());
  if (not firm_str.is_open())
    return false;
  firm_str.seekg(0, firm_str.end);
  const size_t kFileSize = firm_str.tellg();
  firm_str.seekg(0, firm_str.beg);
  // ожидание запроса
  WaitForResponse(out, Packet::kRequest);
  Packet::Sequence seq(&out);
  // инициализация соединения
  char buf[24];
  snprintf(buf, 24, "%u", (unsigned)kFileSize);
  const std::string kMsgs[] = {path, buf};
  SendInitialPkt(seq, kMsgs, 2);
  if (not IsResponse(out, Packet::kRequest)) {
    firm_str.close();
    return false;
  }
  // передача файла
  Array frame(NewFrame());
  size_t was_send     = 0;
  size_t last_percent = 0;
  do {
    firm_str.sync();
    firm_str.read((char*)frame.get(), kFrameSize);
    const size_t kWasRead = firm_str.gcount();
    if (kWasRead != kFrameSize) {
      memset(frame.get() + kWasRead, 0, kFrameSize - kWasRead);
    }
    seq.Send(Packet(Packet::kSTX, frame.get(), kFrameSize));
    was_send += kWasRead;
    if (not IsResponse(out, Packet::kACK)) {
      std::cout << "\t ! Ошибка передачи данных" << std::endl;
      break;
    }
    const size_t kPercent = was_send * 100 / kFileSize;
    if (kPercent > last_percent) {
      ShowPercentage("\t * Прогресс", kPercent);
      last_percent = kPercent;
    }
  } while (was_send < kFileSize);
  std::cout << std::endl;
  seq.Send(Packet(Packet::kEOT));
  IsResponse(out, Packet::kACK);
  seq.Send(Packet(Packet::kEOT));
  IsResponse(out, Packet::kACK);
  IsResponse(out, Packet::kRequest);
  SendClosingPkt(seq);
  firm_str.close();
  return true;
}
开发者ID:Gauraden,项目名称:regiboard,代码行数:55,代码来源:ymodem.cpp


示例3: pcap_open_offline

/**
 *  @todo Add command-line parameters for IPv4 network address and mask so we 
 *        can remove broadcast and multicast hosts from the result
 */
void IPForensics::load_hosts(std::string filename) {
  // open the filename
  char error[PCAP_ERRBUF_SIZE] {};
  pcap_t* pcap = pcap_open_offline(filename.c_str(), error);
  if (pcap == NULL) {
    throw std::runtime_error(error);
  }
  // exit if the data link is not Ethernet
  if (pcap_datalink(pcap) != DLT_EN10MB) {
    pcap_close(pcap);
    throw std::runtime_error("Link-layer type not IEEE 802.3 Ethernet");
  }
  // read the packets from the file
  const unsigned char * packet = NULL;
  struct pcap_pkthdr header;
  // if packet_count_ is set, read specified number of packets only
  if (packet_count_ > 0) {
    for (int i = 0; i < packet_count_; ++i) {
      packet = pcap_next(pcap, &header);
      if (packet != NULL) {
        packets_.push_back(Packet(packet));
      }
    }
  } else {
    // if packet_count_ is not set, read all packets
    packet = pcap_next(pcap, &header);
    while (packet != NULL) {
      packets_.push_back(Packet(packet));
      packet = pcap_next(pcap, &header);
    }
  }
  // close the packet capture
  pcap_close(pcap);
  // extract hosts from packets
  for (Packet p : packets_) {
    // add the source host
    std::set<Host>::iterator it = hosts_.find(static_cast<Host>(p.mac_src()));
    if (it == hosts_.end()) {
      add_host(p.mac_src(), p.ipv4_src(), p.ipv6_src());
    } else {
      update_host(it, p.ipv4_src(), p.ipv6_src());
    }
    // add the destination host
    it = hosts_.find(static_cast<Host>(p.mac_dst()));
    if (it == hosts_.end()) {
      add_host(p.mac_dst(), p.ipv4_dst(), p.ipv6_dst());
    } else {
      update_host(it, p.ipv4_dst(), p.ipv6_dst());
    }
  }
  // remove meaningless hosts
  clean_hosts(nullptr, nullptr);
}
开发者ID:mmaraya,项目名称:ipforensics,代码行数:57,代码来源:ip4and6.cpp


示例4: qDebug

void AVDemuxThread::seekInternal(qint64 pos)
{
    if (audio_thread) {
        audio_thread->setDemuxEnded(false);
        audio_thread->packetQueue()->clear();
    }
    if (video_thread) {
        video_thread->setDemuxEnded(false);
        video_thread->packetQueue()->clear();
    }
    qDebug("seek to %lld ms (%f%%)", pos, double(pos)/double(demuxer->duration())*100.0);
    demuxer->seek(pos);
    // TODO: why queue may not empty?
    if (audio_thread) {
        audio_thread->packetQueue()->clear();
        audio_thread->packetQueue()->put(Packet());
    }
    if (video_thread) {
        video_thread->packetQueue()->clear();
        // TODO: the first frame (key frame) will not be decoded correctly if flush() is called.
        video_thread->packetQueue()->put(Packet());
    }
    //if (subtitle_thread) {
    //     subtitle_thread->packetQueue()->clear();
    //    subtitle_thread->packetQueue()->put(Packet());
    //}
#if RESUME_ONCE_ON_SEEK
    class PauseTask : public QRunnable {
    public:
        PauseTask(AVDemuxThread *dt, bool p)
            : pause(p)
            , demux_thread(dt)
        {}
        void run() {
            if (pause && !demux_thread->isPaused()) // what if user resume?
                demux_thread->pauseInternal(true);
            if (!pause && demux_thread->isPaused())
                demux_thread->pauseInternal(false);
        }
    private:
        bool pause;
        AVDemuxThread *demux_thread;
    };
    pause_tasks.clear();
    if (isPaused()) {
        pause_tasks.enqueue(new PauseTask(this, false));
        pause_tasks.enqueue(new PauseTask(this, true));
    } else {
        pause_tasks.enqueue(new PauseTask(this, true));
    }
#endif
}
开发者ID:bianshifeng,项目名称:QtAV,代码行数:52,代码来源:AVDemuxThread.cpp


示例5: main

int main( int argc, char **argv )
{
    co::init( argc, argv );
    {
        Reader readers[ N_READER ];
        for( size_t i = 0; i < N_READER; ++i )
            readers[i].start();

        co::CommandCache cache;
        co::LocalNodePtr node = new co::LocalNode;
        size_t nOps = 0;

        co::base::Clock clock;
        while( clock.getTime64() < RUNTIME )
        {
            co::Command& command = cache.alloc( node, node, sizeof( Packet ));
            Packet* packet = command.get< Packet >();
            *packet = Packet();

            readers[0].dispatchCommand( command );

            for( size_t i = 1; i < N_READER; ++i )
            {
                co::Command& clone = cache.clone( command );
                readers[i].dispatchCommand( clone );
            }
            ++nOps;
        }

        const uint64_t time = clock.getTime64();
        nOps *= N_READER;
        std::cout << nOps << " operations, " << nOps / time << " ops/ms"
                  << std::endl;

        for( size_t i = 0; i < N_READER; ++i )
        {
            co::Command& command = cache.alloc( node, node, sizeof( Packet ));
            Packet* packet = command.get< Packet >();
            *packet = Packet();
            packet->command = 1;

            readers[i].dispatchCommand( command );
            readers[i].join();
        }
    }

    TEST( co::exit( ));
    return EXIT_SUCCESS;
}
开发者ID:cstalder,项目名称:Equalizer,代码行数:49,代码来源:commandCache.cpp


示例6: Packet

Packet
Packet::make_new(size_t cxt, int ingress_port, packet_id_t id,
                 copy_id_t copy_id, int ingress_length,
                 PacketBuffer &&buffer, PHVSourceIface *phv_source) {
  return Packet(cxt, ingress_port, id, copy_id, ingress_length,
                std::move(buffer), phv_source);
}
开发者ID:wysamuel,项目名称:behavioral-model,代码行数:7,代码来源:packet.cpp


示例7: while

void Receiver::enterRVIMode(){
	int flag;
	int tCount = 0 ;
	pSerial_->sendPacket(Packet(RVI));
	while(true){
		try{
			flag = pSerial_->getPacket().flags();
			if (flag == ACK1){
				break;
			}
		}catch(int i){
			ENSURE_EXCEPTION(i, TIMEOUT_EXCEPTION);
				throw GOTO_RESET_EXCEPTION;

		}
	}

	while(!(pBuffer_->safe())){
		pSerial_->sendPacket((pBuffer_->peek()));
		pBuffer_->pop();	
	}
	if(pBuffer_->safe()){
		throw GOTO_IDLE_EXCEPTION;
	}
}
开发者ID:AshuDassanRepo,项目名称:bcit-courses,代码行数:25,代码来源:Receiver.cpp


示例8: AckPackets

void CRemoteConnection::ProcessRawPacket(const unsigned char* data, const unsigned length)
{
	lastReceiveTime=static_cast<float>(SDL_GetTicks())/1000.0f;

	const unsigned hsize = 9;
	int packetNum=*(int*)data;
	int ack=*(int*)(data+4);
	unsigned char nak = *(unsigned char*)(data+8);

	AckPackets(ack);

	if (nak > 0)	// we have lost $nak packets
	{
		int nak_abs = nak + firstUnacked - 1;
		if (nak_abs!=lastNak || lastNakTime < lastReceiveTime-0.1f)
		{
			// resend all packets from firstUnacked till nak_abs
			lastNak=nak_abs;
			lastNakTime=lastReceiveTime;
			for(int b=firstUnacked;b<=nak_abs;++b){
				SendRawPacket(unackedPackets[b-firstUnacked]->data,unackedPackets[b-firstUnacked]->length,b);
				++resentPackets;
			}
		}
	}

	if(!active || lastInOrder>=packetNum || waitingPackets.find(packetNum)!=waitingPackets.end())
		return;

	Packet* p=SAFE_NEW Packet(data+hsize,length-hsize);
	waitingPackets[packetNum]=p;

	dataRecv += length;
	recvOverhead += hsize;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:35,代码来源:RemoteConnection.cpp


示例9: Packet

Packet PacketPool::allocate(int size)
{
	if (size <= 0)
		return Packet();
	Packet ret(m_pages[m_alloc_page].get(), m_alloc_ptr, size);

	// Advance the allocation location
	m_alloc_ptr += size;
	// If there is not enough room in the current page
	if (m_alloc_ptr >= m_page_size - m_packet_size) {
		// Try to find an empty one
		unsigned int i;
		for (i = 0; i < m_pages.size(); i++) {
			if (*reinterpret_cast<unsigned int*>(m_pages[i].get()) == 0) {
				break;
			}
		}
		m_alloc_page = i;
		m_alloc_ptr = PAGE_HEADER_SIZE;
		// If the page doesn't exist create it
		if (i == m_pages.size()) {
			add_page();
		}
	}

	return ret;
}
开发者ID:bqqbarbhg,项目名称:netgame,代码行数:27,代码来源:packet.cpp


示例10: Packet

Packet Packet::fromAVPacket(const AVPacket *avpkt, double time_base)
{
    Packet pkt;
    if (fromAVPacket(&pkt, avpkt, time_base))
        return pkt;
    return Packet();
}
开发者ID:karvaporo,项目名称:QtAV,代码行数:7,代码来源:Packet.cpp


示例11: log_func

void Conn::onRead(const boost::system::error_code& error, std::shared_ptr< boost::asio::streambuf > rd_buf) {
	if( unlikely(error) ) {
		log_func("[iproto_conn] %s:%u read error: %s", ep.address().to_string().c_str(), ep.port(), error.message().c_str() );
		dismissCallbacks(CB_ERR);
		if( error != boost::asio::error::operation_aborted ) {
			reconnect();
		}
		return;
	}
	if( unlikely(!rd_buf) )
		rd_buf.reset(new boost::asio::streambuf);
	if( LOG_DEBUG )
		log_func("[iproto_conn] %s:%u onRead rd_buf->size=%zu", ep.address().to_string().c_str(), ep.port(), rd_buf->size());
	while( rd_buf->size() >= sizeof(Header) ) {
		const PacketPtr *buf = boost::asio::buffer_cast< const PacketPtr * >( rd_buf->data() );
		if( LOG_DEBUG )
			log_func("[iproto_conn] %s:%u onRead buffer iproto packet hdr: len=%u sync=%u msg=%u", ep.address().to_string().c_str(), ep.port(),
				buf->hdr.len, buf->hdr.sync, buf->hdr.msg);
		size_t want_read = sizeof(Header)+buf->hdr.len;
		if( want_read <= rd_buf->size() ) {
			invokeCallback(buf->hdr.sync, RequestResult(CB_OK, Packet(buf)) );
			rd_buf->consume( sizeof(Header) + buf->hdr.len );
		}else{
			size_t rd = want_read - rd_buf->size();
			if( LOG_DEBUG )
				log_func("[iproto_conn] %s:%u onRead want_read=%zu", ep.address().to_string().c_str(), ep.port(), rd);
			boost::asio::async_read(sock, *rd_buf, boost::asio::transfer_at_least(rd),
				boost::bind(&Conn::onRead, shared_from_this(), boost::asio::placeholders::error, rd_buf) );
			return;
		}
	}
	if( likely(sock.is_open()) )
		boost::asio::async_read(sock, *rd_buf, boost::asio::transfer_at_least(sizeof(Header)-rd_buf->size()),
			boost::bind(&Conn::onRead, shared_from_this(), boost::asio::placeholders::error, rd_buf) );
}
开发者ID:PSIAlt,项目名称:asio-libs,代码行数:35,代码来源:iproto_conn.cpp


示例12: Packet

void DropsPacket::removeDrop(vector <Player*> players, Drop* drop){
	Packet packet = Packet();
	packet.addHeader(0xBA);
	packet.addByte(0);
	packet.addInt(drop->getObjID());
	packet.sendTo(NULL, players, 1);
}
开发者ID:Dephon,项目名称:MapleStory_tms,代码行数:7,代码来源:DropsPacket.cpp


示例13: while

bool CDSMSplitterFilter::DemuxLoop()
{
    HRESULT hr = S_OK;

    while (SUCCEEDED(hr) && !CheckRequest(nullptr) && m_pFile->GetRemaining()) {
        dsmp_t type;
        UINT64 len;

        if (!m_pFile->Sync(type, len)) {
            continue;
        }

        __int64 pos = m_pFile->GetPos();

        if (type == DSMP_SAMPLE) {
            CAutoPtr<Packet> p(DEBUG_NEW Packet());
            if (m_pFile->Read(len, p)) {
                if (p->rtStart != Packet::INVALID_TIME) {
                    p->rtStart -= m_pFile->m_rtFirst;
                    p->rtStop -= m_pFile->m_rtFirst;
                }

                hr = DeliverPacket(p);
            }
        }

        m_pFile->Seek(pos + len);
    }

    return true;
}
开发者ID:Blitzker,项目名称:mpc-hc,代码行数:31,代码来源:DSMSplitter.cpp


示例14: sendPacket

//
// bool sendMsg(msg, toID, fromID, type)
// Last modified: 07Sep2006
//
// Attempts to send a packet to its destination
// based upon the given parameters, returning
// true if successful, false otherwise.
//
// Returns:     true if successful, false otherwise
// Parameters:
//      msg     in/out  the message being sent
//      toID    in      the ID of the cell receiving the packet
//      fromID  in      the ID of the cell sending the packet
//      type    in      the type of message being sent
//
bool Environment::sendMsg(const Message &msg,
                          const GLint    toID,
                          const GLint    fromID,
                          const GLint    type)
{
    return sendPacket(Packet(msg, toID, fromID, type));
}   // sendMsg(const Message &, const GLint, const GLint, const GLint)
开发者ID:dtbinh,项目名称:lego-rover-formation,代码行数:22,代码来源:Environment.cpp


示例15: Packet

bool KOSocket::DecryptPacket(uint8 *in_stream, Packet & pkt)
{
    uint8* final_packet = nullptr;

    if (isCryptoEnabled())
    {
        // Invalid packet (all encrypted packets need a CRC32 checksum!)
        if (m_remaining < 4
                // Invalid checksum
                || m_crypto.JvDecryptionWithCRC32(m_remaining, in_stream, in_stream) < 0
                // Invalid sequence ID
                || ++m_sequence != *(uint32 *)(in_stream))
            return false;

        m_remaining -= 8; // remove the sequence ID & CRC checksum
        final_packet = &in_stream[4];
    }
    else
    {
        final_packet = in_stream; // for simplicity :P
    }

    m_remaining--;
    pkt = Packet(final_packet[0], (size_t)m_remaining);
    if (m_remaining > 0)
    {
        pkt.resize(m_remaining);
        memcpy((void*)pkt.contents(), &final_packet[1], m_remaining);
    }

    return true;
}
开发者ID:nikos32,项目名称:snoxd-koserver,代码行数:32,代码来源:KOSocket.cpp


示例16: Packet

UINT CPacketQueue::Push(const string &Name, const CVariant& Data, int iPriority/*, uint32 uTTL*/)
{
	SVarPacket Packet(Name, Data, iPriority);
	Packet.Data.Freeze();
	ASSERT(Packet.Data.IsFrozen());
	Packet.uID = ++m_uLastID;
	/*if(uTTL != -1)
		Packet.uTTL = GetCurTick() + uTTL;*/

	m_QueueSize += Packet.Data.GetSize() + Packet.Name.size();

	if(iPriority)
	{
		//deque<SVarPacket>::iterator I = find_if(m_Queue.begin(), m_Queue.end(), ...);
		deque<SVarPacket>::iterator first = m_Queue.begin();
		deque<SVarPacket>::iterator last = m_Queue.end();
		for (; first != last; ++first) 
		{
			if (first->iPriority < iPriority) // find the first packet that has a lower priority than ours and insert it befoure it
			{ 
				last = first;
				break;
			}
		}
		m_Queue.insert(last, Packet);
	}
	else
		m_Queue.push_back(Packet);

	return m_uLastID;
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:31,代码来源:PacketQueue.cpp


示例17: outLogFile

void Node::PacketGenerating(int time){//节点是否产生数据包,以及能量消耗
	if(m_Battery->GetEnergyGrade() <= 0){
		ofstream outLogFile("log.txt", ios_base::out | ios_base::app);
		assert(!outLogFile.fail());
		outLogFile<<__TIME__<<"节点"<<id<<"电池耗尽啦><"<<endl;
		outLogFile.close();
		return;
	}
	double pos = (double) (rand() + 1) / (double)RAND_MAX;
	if(time % SENSE_DURATION == 1){//因为是从第一秒开始计算的么
		if(pos <= POSIBILITY_PACKET_GENERATING){//产生数据包
			bufferedPackets.push(Packet(id, MAX_TIME));
		}
		if(currentWorkState == Sleeping){
			return;
		}
		
		int i = 0;
		while(!bufferedPackets.empty() && i < MAX_PACKETS_PER_SLOT){
			//RoutingWithBufferedPackets();
			bufferedPackets.pop();
			++i;
		}
		if(bufferedPackets.empty() && currentState == NonGatewayNode){
			pos = (double) (rand() + 1) / (double)RAND_MAX;
			if(pos <= POSIBILITY_PACKET_GENERATING){
				currentWorkState = Sleeping;
				workingTime = 0;
				relaxingTime = 0;
			}
		}
	}
}
开发者ID:ChunmeiZhang915,项目名称:BatteryRecovery,代码行数:33,代码来源:Node.cpp


示例18: resize

void PktVector::push_back(const u_char *packet, u_int8_t ifType){
    if(m_size >= m_capacity)
        resize();
    m_collection[m_size] = Packet(packet,ifType);
    m_collection[m_size].SetPtrsToNull();
    m_size++;
}
开发者ID:dmitsov,项目名称:PuzzleGame,代码行数:7,代码来源:PacketVector.cpp


示例19: runSetup

void Network::runSetup() {
    for (int i=0; i<MAX_NODES; i++) {
        if (nodes[i]) {
            nodes[i]->process(Packet(MsgSetup), -1);
        }
    }
}
开发者ID:pgreenwood,项目名称:microflo,代码行数:7,代码来源:microflo.cpp


示例20: qWarning

void LoopPlayer::addFrame(const QByteArray &packet, int seq) {
	if (DOUBLE_RAND < g.s.dPacketLoss) {
		qWarning("Drop");
		return;
	}

	bool restart = (qtLastFetch.elapsed() > 100);

	{
		QMutexLocker l(&qmLock);

		double time = qtTicker.elapsed();

		double r;
		if (restart)
			r = 0.0;
		else
			r = DOUBLE_RAND * g.s.dMaxPacketDelay;

		qmPackets.insert(static_cast<float>(time + r), Packet(seq, packet));
	}

	// Restart check
	if (qtLastFetch.elapsed() > 100) {
		AudioOutputPtr ao = g.ao;
		if (ao) {
			ao->addFrameToBuffer(this, QByteArray(), 0);
		}
	}

}
开发者ID:ArminW,项目名称:re-whisper,代码行数:31,代码来源:Audio.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PacketAlertCheck函数代码示例发布时间:2022-05-30
下一篇:
C++ Pack函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap