Added stop function to udp client

parent 1ff5d248
......@@ -11,20 +11,21 @@ using namespace std;
UDPClient::~UDPClient()
{
if (enet_socket_shutdown(discoverSocket, ENET_SOCKET_SHUTDOWN_READ_WRITE) != 0)
stop();
}
void UDPClient::stop()
{
if (discoverSocket != ENET_SOCKET_NULL)
{
cerr << "eNet: Failed to shutdown discover socket" << endl;
enet_socket_destroy(discoverSocket);
}
enet_socket_destroy(discoverSocket);
if (enet_socket_shutdown(dataSocket, ENET_SOCKET_SHUTDOWN_READ_WRITE) != 0)
if (dataSocket != ENET_SOCKET_NULL)
{
cerr << "eNet: Failed to shutdown data socket" << endl;
enet_socket_destroy(dataSocket);
}
enet_socket_destroy(dataSocket);
discoverSocket = ENET_SOCKET_NULL;
dataSocket = ENET_SOCKET_NULL;
......
......@@ -26,6 +26,7 @@ public:
~UDPClient();
bool start(enet_uint16 discoverPort, enet_uint16 dataPort, bool bindDataSocket = true);
void stop();
void sendPacket(enet_uint32 host, enet_uint16 port, PacketType type, void *data, size_t dataLength);
......@@ -37,6 +38,7 @@ public:
return paused;
}
protected:
bool started = false;
std::thread networkThread;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment