void GDNetHost::poll_events() { ENetEvent event; if (enet_host_service(_host, &event, _event_wait) > 0) { _event_queue.push(new_event(event)); while (enet_host_check_events(_host, &event) > 0) { _event_queue.push(new_event(event)); } } }
int Connection::event_service(int timer){ int retr; if(!(retr=enet_host_check_events (conn,&event))) //Get an event from the stack. retr=enet_host_service(conn, &event,timer); //If one is not avalible, wait 'timer' miliseconds for one. if(event.type==ENET_EVENT_TYPE_CONNECT){ lastConnection.host = event.peer -> address.host; lastConnection.port = event.peer -> address.port; peerID=event.peer -> incomingPeerID; } else if(event.type==ENET_EVENT_TYPE_RECEIVE){ lastConnection.host = event.peer -> address.host; lastConnection.port = event.peer -> address.port; peerID=event.peer -> incomingPeerID; packetLength = event.packet -> dataLength; packetData = event.packet -> data; } else if(event.type==ENET_EVENT_TYPE_DISCONNECT){ lastConnection.host = event.peer -> address.host; lastConnection.port = event.peer -> address.port; peerID=event.peer -> incomingPeerID; } return retr; }