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

C++ enet_packet_destroy函数代码示例

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

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



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

示例1: while

        void ServerBase::update(void)
        {
            if (!mIsRunning)
                return;

            ENetEvent event;
            while (enet_host_service(mInternalHost, &event, 0) > 0)
            {
                switch(event.type)
                {
                    case ENET_EVENT_TYPE_CONNECT:
                    {
                        IncomingClientBase *client = new Kiaro::Network::IncomingClientBase(event.peer, this);
                        event.peer->data = client;

                        mConnectedClientSet.insert(mConnectedClientSet.end(), (size_t)client);
                        onClientConnected(client);

                        break;
                    }

                    case ENET_EVENT_TYPE_DISCONNECT:
                    {
                        Kiaro::Network::IncomingClientBase *disconnected = (Kiaro::Network::IncomingClientBase*)event.peer->data;
                        onClientDisconnected(disconnected);

                        mConnectedClientSet.erase((size_t)disconnected);
                        delete disconnected;

                        break;
                    }

                    case ENET_EVENT_TYPE_RECEIVE:
                    {
                        if (!event.peer->data)
                        {
                            enet_packet_destroy(event.packet);
                            throw std::runtime_error("ServerBase: Invalid ENet peer data on packet receive!");
                        }

                        Kiaro::Network::IncomingClientBase *sender = (Kiaro::Network::IncomingClientBase*)event.peer->data;
                        Kiaro::Support::BitStream incomingStream(event.packet->data, event.packet->dataLength, event.packet->dataLength);

                        onReceivePacket(incomingStream, sender);
                        enet_packet_destroy(event.packet);

                        break;
                    }

                    case ENET_EVENT_TYPE_NONE:
                        break;
                }
            }
        }
开发者ID:Ragora,项目名称:KGE,代码行数:54,代码来源:ServerBase.cpp


示例2: enet_packet_create

// ----------------------------------------------------------------------------
ENetPacket* Crypto::encryptSend(BareNetworkString& ns, bool reliable)
{
    // 4 bytes counter and 4 bytes tag
    ENetPacket* p = enet_packet_create(NULL, ns.m_buffer.size() + 8,
        (reliable ? ENET_PACKET_FLAG_RELIABLE :
        (ENET_PACKET_FLAG_UNSEQUENCED | ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT))
        );
    if (p == NULL)
        return NULL;

    std::array<uint8_t, 12> iv = {};
    std::unique_lock<std::mutex> ul(m_crypto_mutex);

    uint32_t val = ++m_packet_counter;
    if (NetworkConfig::get()->isClient())
        memcpy(iv.data(), &val, 4);
    else
        memcpy(iv.data() + 4, &val, 4);

    uint8_t* packet_start = p->data + 8;

    if (EVP_EncryptInit_ex(m_encrypt, NULL, NULL, NULL, iv.data()) != 1)
    {
        enet_packet_destroy(p);
        return NULL;
    }

    int elen;
    if (EVP_EncryptUpdate(m_encrypt, packet_start, &elen, ns.m_buffer.data(),
        (int)ns.m_buffer.size()) != 1)
    {
        enet_packet_destroy(p);
        return NULL;
    }
    if (EVP_EncryptFinal_ex(m_encrypt, unused_16_blocks.data(), &elen) != 1)
    {
        enet_packet_destroy(p);
        return NULL;
    }
    if (EVP_CIPHER_CTX_ctrl(m_encrypt, EVP_CTRL_GCM_GET_TAG, 4, p->data + 4)
        != 1)
    {
        enet_packet_destroy(p);
        return NULL;
    }
    ul.unlock();

    memcpy(p->data, &val, 4);
    return p;
}   // encryptSend
开发者ID:qwertychouskie,项目名称:stk-code,代码行数:51,代码来源:crypto_openssl.cpp


示例3: while

void Purity::Server::handleEvents()
{
    ENetEvent event;
    NetworkAction action;

    while (enet_host_service(mHost, &event, 0) > 0)
    {
        switch (event.type)
        {
        case ENET_EVENT_TYPE_CONNECT:
            std::cout << "New peer!" << std::endl;
            break;

        case ENET_EVENT_TYPE_DISCONNECT:
            std::cout << "Peer disconnected!" << std::endl;
            break;
        case ENET_EVENT_TYPE_RECEIVE:
            memcpy(&action, event.packet->data, event.packet->dataLength);

            std::cout << action.objectName << " is performing " << action.actionName << std::endl;

            mReceivedActionQueue->push(action);

            enet_packet_destroy(event.packet);

            break;

        default:
            std::cout << "Default!\n";
        }
    }
}
开发者ID:TapkaiNKooH,项目名称:Purity2D,代码行数:32,代码来源:server.cpp


示例4: while

void NetworkLayerENet::listen(ENetHost* host, ENetEvent& last_host_event, NetworkEventHandler& listener)
{
    while (enet_host_service(host, &last_host_event, 0) > 0)
    {
        switch (last_host_event.type)
        {
            case ENET_EVENT_TYPE_CONNECT:
            {
                NetPeerENet* peer = new NetPeerENet(last_host_event.peer);
                listener.onConnect(peer);
            }
            break;

            case ENET_EVENT_TYPE_RECEIVE:
            {
                NetPeerENet peer(last_host_event.peer);
                listener.onReceive(peer, last_host_event.packet->data, last_host_event.packet->dataLength);
                enet_packet_destroy(last_host_event.packet);
            }
            break;

            case ENET_EVENT_TYPE_DISCONNECT:
            {
                NetPeerENet peer(last_host_event.peer);
                listener.onDisconnect(peer);
            }
            break;

            default:
            break;
        }
    }
}
开发者ID:HerbFargus,项目名称:supermariowar,代码行数:33,代码来源:NetworkLayerENet.cpp


示例5: enet_peer_disconnect

bool udp_client::disconnect()
{
    if (!is_connected())
        return false;

    ENetEvent ev;
    enet_peer_disconnect(peer_, 0);

    {
        boost::lock_guard<boost::mutex> lock(host_mutex_);
        while (enet_host_service(host_, &ev, 3000)) {
            switch (ev.type) {
            case ENET_EVENT_TYPE_DISCONNECT:
                connected_ = false;
                log_msg("udp_client disconnected");
                return true;

            default:
                enet_packet_destroy(ev.packet);
            }
        }
    }

    log_msg("udp_client disconnect failed");
    enet_peer_reset(peer_);
    return false;
}
开发者ID:Nocte-,项目名称:hexahedra,代码行数:27,代码来源:udp_client.cpp


示例6: enet_peer_remove_incoming_commands

static void
enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand)
{
    ENetListIterator currentCommand;    
    
    for (currentCommand = startCommand; currentCommand != endCommand; )
    {
       ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand;

       currentCommand = enet_list_next (currentCommand);

       enet_list_remove (& incomingCommand -> incomingCommandList);
 
       if (incomingCommand -> packet != NULL)
       {
          -- incomingCommand -> packet -> referenceCount;

          if (incomingCommand -> packet -> referenceCount == 0)
            enet_packet_destroy (incomingCommand -> packet);
       }

       if (incomingCommand -> fragments != NULL)
         enet_free (incomingCommand -> fragments);

       enet_free (incomingCommand);
    }
}
开发者ID:7histle,项目名称:openspades,代码行数:27,代码来源:peer.c


示例7: while

    bool Client::update()
    {
        bool dataChanged = false;
        ENetEvent event;

        while(enet_host_service(m_client, &event, 2))
        {
            switch(event.type)
            {
                case ENET_EVENT_TYPE_CONNECT:
                    LOG(INFO) << "Client connected successfully to " << event.peer->address.host
                              << ":" << event.peer->address.port << ".";
                    m_connected = true;
                    dataChanged = true;
                    break;
                case ENET_EVENT_TYPE_DISCONNECT:
                    event.peer->data = nullptr;
                    LOG(INFO) << "Client disconnected.";
                    m_serverPeer = nullptr;
                    m_connected = false;
                    dataChanged = true;
                    break;
                case ENET_EVENT_TYPE_NONE:
                    //Nothing happened
                    break;
                case ENET_EVENT_TYPE_RECEIVE:
                    dataChanged = receivePacket(event.packet, event.peer);
                    enet_packet_destroy(event.packet);
                    break;
            }
        }
        return dataChanged;
    }
开发者ID:maximaximal,项目名称:piga,代码行数:33,代码来源:Client.cpp


示例8: enet_peer_disconnect

void NetPlayClient::Disconnect()
{
	ENetEvent netEvent;
	m_connecting = false;
	m_state = Failure;
	if (m_server)
		enet_peer_disconnect(m_server, 0);
	else
		return;

	while (enet_host_service(m_client, &netEvent, 3000) > 0)
	{
		switch (netEvent.type)
		{
		case ENET_EVENT_TYPE_RECEIVE:
			enet_packet_destroy(netEvent.packet);
			break;
		case ENET_EVENT_TYPE_DISCONNECT:
			m_server = nullptr;
			return;
		default:
			break;
		}
	}
	//didn't disconnect gracefully force disconnect
	enet_peer_reset(m_server);
	m_server = nullptr;
}
开发者ID:moncefmechri,项目名称:dolphin,代码行数:28,代码来源:NetPlayClient.cpp


示例9: result

void udp_server::poll (uint16_t milliseconds)
{
    ENetEvent ev;
    auto result (enet_host_service(sv_, &ev, milliseconds));

    if (result < 0)
        throw std::runtime_error((format("network error %1%") % -result).str());

    switch (ev.type)
    {
        case ENET_EVENT_TYPE_CONNECT:
            on_connect(ev.peer);
            break;

        case ENET_EVENT_TYPE_RECEIVE:
            on_receive(ev.peer, packet(ev.packet->data, ev.packet->dataLength));
            enet_packet_destroy(ev.packet);
            break;

        case ENET_EVENT_TYPE_DISCONNECT:
            on_disconnect(ev.peer);
            break;

        case ENET_EVENT_TYPE_NONE:
            break;
    }
}
开发者ID:Cosmotronic,项目名称:hexahedra,代码行数:27,代码来源:udp_server.cpp


示例10: net_controller_free

void net_controller_free(controller *ctrl) {
    wtf *data = ctrl->data;
    ENetEvent event;
    if (!data->disconnected) {
        DEBUG("closing connection");
        enet_peer_disconnect(data->peer, 0);

        while (enet_host_service(data->host, &event, 3000) > 0) {
            switch (event.type) {
                case ENET_EVENT_TYPE_RECEIVE:
                    enet_packet_destroy(event.packet);
                    break;
                case ENET_EVENT_TYPE_DISCONNECT:
                    DEBUG("got disconnect notice");
                    // peer has acknowledged the disconnect
                    goto done;
                    break;
                default:
                    break;
            }
        }
    }
done:
    if(data->host) {
        enet_host_destroy(data->host);
        data->host = NULL;
    }
    if(ctrl->data) {
        free(ctrl->data);
        ctrl->data = NULL;
    }
}
开发者ID:gdeda,项目名称:openomf,代码行数:32,代码来源:net_controller.c


示例11: while

void Server::updateNet() {
	ENetEvent event;
	while (enet_host_service(host, &event, 0) > 0) {
		switch (event.type) {
		case ENET_EVENT_TYPE_CONNECT:
			handleConnect(event.peer);
			break;
		case ENET_EVENT_TYPE_DISCONNECT:
			handleDisconnect(event.peer, (DisconnectReason) event.data);
			break;
		case ENET_EVENT_TYPE_RECEIVE:
			handlePacket(
				event.packet->data,
				event.packet->dataLength,
				event.channelID,
				event.peer
				);
			enet_packet_destroy(event.packet);
			break;
		default:
			LOG_WARNING(logger) << "Received unknown ENetEvent type << event.type";
			break;
		}
	}
}
开发者ID:Backson,项目名称:3dgamecpp,代码行数:25,代码来源:server.cpp


示例12: while

	bool NetworkHost::update()
	{
		if (!host)
			return false;
		
		ENetEvent event;
		while (enet_host_service(host, &event, 0) > 0)
		{
			switch (event.type)
			{
			case ENET_EVENT_TYPE_CONNECT:
			{
				NetworkConnection *newconn = new NetworkConnection(event.peer);
				event.peer->data = newconn;
				newconnections.push(newconn);
				break;
			}
			case ENET_EVENT_TYPE_RECEIVE:
			{
				// Push received data into connection
				Buffer *buffer = new Buffer(event.packet->data, event.packet->dataLength, true);
				NetworkConnection* con = ((NetworkConnection*) event.peer->data);
				con->injectData((BufferPointer) buffer);
				enet_packet_destroy(event.packet);
				break;
			}
			case ENET_EVENT_TYPE_DISCONNECT:
				((NetworkConnection*) event.peer->data)->close();
				break;
			default:
				break;
			}
		}
		return true;
	}
开发者ID:mgottschlag,项目名称:PeakEngineOld,代码行数:35,代码来源:NetworkHost.cpp


示例13: enet_peer_disconnect

void NNetwork::Disconnect()
{
    if (!Host)
    {
        return;
    }
    enet_peer_disconnect(Host,0);
    ENetEvent Event;
    while (enet_host_service(Client,&Event,1000) > 0)
    {
        switch (Event.type)
        {
        case ENET_EVENT_TYPE_RECEIVE:
        {
            enet_packet_destroy(Event.packet);
            break;
        }
        case ENET_EVENT_TYPE_DISCONNECT:
        {
            GetGame()->GetLog()->Send("NETWORK",2,std::string("Successfully disconnected with ") + HostName + ".");
            Host = NULL;
            return;
        }
        default:
            GetGame()->GetLog()->Send("NET",1,"Certain events not implemented! FIXME");
            break;
        }
    }
    GetGame()->GetLog()->Send("NETWORK",1,"Server didn't respond to disconnect!");
    enet_peer_reset(Host);
    Host = NULL;
}
开发者ID:ZenX2,项目名称:Astrostruct,代码行数:32,代码来源:NNetwork.cpp


示例14: while

void* NetworkManager::threadConnexion(void* arguments)
{
	NetworkManager * networkManager = static_cast<NetworkManager *>(arguments) ;

	while ((enet_host_service (networkManager->client,&networkManager->eventClient, 10) >= 0 ) && (networkManager->endThread == false )  )
	{
		switch (networkManager->eventClient.type)
		{
		case ENET_EVENT_TYPE_CONNECT:
			networkManager->callback((XSILIUM_ALL * 1000) + ID_CONNEXION);
			break;
		case ENET_EVENT_TYPE_RECEIVE:
		{
			MessagePacket * message = new MessagePacket();

			std::istringstream archive_stream(std::string((char*)networkManager->eventClient.packet->data));
			boost::archive::text_iarchive archive(archive_stream);
			archive >> message;

			networkManager->callback(message->getOpcode(),message);
			break;
		}

		case ENET_EVENT_TYPE_DISCONNECT:
			networkManager->callback((XSILIUM_ALL * 1000 ) + ID_DECONEXION);
			networkManager->endThread = true;
			break;
		default:
			break;
		}
        enet_packet_destroy (networkManager->eventClient.packet);
	}
	return NULL;
}
开发者ID:quinsmpang,项目名称:xsilium-engine,代码行数:34,代码来源:NetworkManager.cpp


示例15: enet_peer_disconnect

void NetworkManager::disconnexion()
{
	if(peer != NULL)
	{
		if(isConnectedflag)
		{
			isConnectedflag = false;
		}
		enet_peer_disconnect (peer, 0);
	    /* Allow up to 3 seconds for the disconnect to succeed
	       and drop any packets received packets.
	     */
		while (enet_host_service (client, & eventClient, 3000) > 0)
		{
			switch (eventClient.type)
			{
			case ENET_EVENT_TYPE_RECEIVE:
				enet_packet_destroy (eventClient.packet);
				break;
			case ENET_EVENT_TYPE_DISCONNECT:
				puts ("Disconnection succeeded.");
				break;
			default:
				break;
			}
		}

		enet_peer_reset (peer);
	}

}
开发者ID:respu,项目名称:xsilium-engine,代码行数:31,代码来源:NetworkManager.cpp


示例16: while

    void Host::process()
    {
        // check for data
        ENetEvent event;
        while (enet_host_service(mClient, &event, 0) > 0)
        {
            switch (event.type)
            {
            case ENET_EVENT_TYPE_CONNECT:
                {
                    mConnected = true;
                } break;

            case ENET_EVENT_TYPE_RECEIVE:
                {
                    Packet *packet = new Packet((char*)event.packet->data,
                                                event.packet->dataLength);
                    mPackets.push_back(packet);
                    enet_packet_destroy (event.packet);
                } break;

            case ENET_EVENT_TYPE_DISCONNECT:
                {
                    mConnected = false;
                } break;
            }
        }
    }
开发者ID:suprafun,项目名称:smalltowns,代码行数:28,代码来源:host.cpp


示例17: enet_packet_destroy

Event::~Event()
{
	if( Type == EVENT_FORM_INTERACTION )
	{
		if( Data.Forms.AdditionalData != nullptr )
		{
			delete Data.Forms.AdditionalData;
		}
	}

#ifdef NETWORK_SUPPORT
	if( Type == EVENT_NETWORK_PACKET_RECEIVED )
	{
		enet_packet_destroy( Data.Network.Traffic.packet );
	}
#endif

#ifdef DOWNLOAD_SUPPORT
	if( Type == EVENT_DOWNLOAD_COMPLETE || Type == EVENT_DOWNLOAD_PROGRESS )
	{
		if( URL != 0 )
		{
			delete URL;
		}
		if( Contents != 0 )
		{
			delete Contents;
		}
	}
#endif

}
开发者ID:SolariusScorch,项目名称:OpenApoc,代码行数:32,代码来源:event.cpp


示例18: main

int main (int argc, char * const argv[]) {
    
    if(enet_initialize() != 0)
	{
		printf("An error occurred while initializing ENet.\n");
	}
	
	ENetAddress address;
	ENetHost* server;
	
	address.host = ENET_HOST_ANY;
	address.port = 9050;
	
	// up to 32 clients with unlimited bandwidth
	server = enet_host_create(&address, 32, 0, 0);
	if(server == NULL)
	{
		printf("An error occurred while trying to create an ENet server host.\n");
	}
	
	int clients = 0;
	
	// server main loop
	while(true)
	{
		ENetEvent event;
		while(enet_host_service(server, &event, 1000) > 0)
		{
			switch(event.type)
			{
				case ENET_EVENT_TYPE_CONNECT:
					printf ("A new client connected from %x:%u.\n", 
							event.peer -> address.host,
							event.peer -> address.port);
					
					clients++;
					
					break;
					
				case ENET_EVENT_TYPE_RECEIVE:
					printf ("A packet of length %u containing %s was received.\n",
							event.packet->dataLength,
							event.packet->data);
					
					ENetPacket* packet = enet_packet_create(event.packet->data, event.packet->dataLength, ENET_PACKET_FLAG_RELIABLE);
					enet_host_broadcast(server, 0, packet);
					enet_host_flush(server);
					
					enet_packet_destroy(event.packet);
					break;
					
				case ENET_EVENT_TYPE_DISCONNECT:
					printf("Client disconnected.\n");
					event.peer->data = NULL;
			}
		}
	}
	
	return 0;
}
开发者ID:simudream,项目名称:oolong,代码行数:60,代码来源:main.cpp


示例19: enet_packet_destroy

Event::~Event()
{

#ifdef NETWORK_SUPPORT
	if( Type == EVENT_NETWORK_PACKET_RECEIVED )
	{
		enet_packet_destroy( Data.Network.Traffic.packet );
	}
#endif

#ifdef DOWNLOAD_SUPPORT
	if( Type == EVENT_DOWNLOAD_COMPLETE || Type == EVENT_DOWNLOAD_PROGRESS )
	{
		if( Data.Download.URL != nullptr )
		{
			delete Data.Download.URL;
		}
		if( Data.Download.Contents != nullptr )
		{
			delete Data.Download.Contents;
		}
	}
#endif

}
开发者ID:pmprog,项目名称:0Wave,代码行数:25,代码来源:event.cpp


示例20: enet_peer_disconnect

	void CClienteENet::disconnect(CConexion* conexion)
	{
		ENetEvent event;
    
		enet_peer_disconnect (((CConexionENet*)conexion)->getENetPeer(),0);

		/* Allow up to 3 seconds for the disconnect to succeed
			and drop any packets received packets.     */
		while (enet_host_service (client, & event, 50) > 0)
		{
			switch (event.type)
			{
			case ENET_EVENT_TYPE_RECEIVE:
				enet_packet_destroy (event.packet);
				break;

			case ENET_EVENT_TYPE_DISCONNECT:
				if(DEBUG_CLIENT)
					fprintf (stdout, "Disconnection succeeded.");
					disconnectReceived(conexion);
				return;
			}
		}
	    
		/* We've arrived here, so the disconnect attempt didn't */
		/* succeed yet.  Force the connection down.             */
		enet_peer_reset (((CConexionENet*)conexion)->getENetPeer());
		disconnectReceived(conexion);

		if(DEBUG_CLIENT)
			fprintf(stdout, "Disconnection Forced");

		if(listaConexiones.empty())
			estado = INIT_NOT_CONNECTED;
	}
开发者ID:franaisa,项目名称:Gloom,代码行数:35,代码来源:clienteENet.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ enet_peer_reset函数代码示例发布时间:2022-05-30
下一篇:
C++ enet_packet_create函数代码示例发布时间: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