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


C++ enet_packet_destroy函数代码示例

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


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


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