From 44d7207a1c288f216c4d1fa517b8fb0aa94bc001 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 9 Mar 2015 18:37:02 +0100 Subject: NetPlay: add a Common/ENetUtil namespace Move WakeupThread in it --- Source/Core/Common/ENetUtil.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Source/Core/Common/ENetUtil.cpp (limited to 'Source/Core/Common/ENetUtil.cpp') diff --git a/Source/Core/Common/ENetUtil.cpp b/Source/Core/Common/ENetUtil.cpp new file mode 100644 index 0000000000..7269893f90 --- /dev/null +++ b/Source/Core/Common/ENetUtil.cpp @@ -0,0 +1,28 @@ +// Copyright 2015 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "ENetUtil.h" + +namespace ENetUtil +{ + +void WakeupThread(ENetHost* host) +{ + // Send ourselves a spurious message. This is hackier than it should be. + // comex reported this as https://github.com/lsalzman/enet/issues/23, so + // hopefully there will be a better way to do it in the future. + ENetAddress address; + if (host->address.port != 0) + address.port = host->address.port; + else + enet_socket_get_address(host->socket, &address); + address.host = 0x0100007f; // localhost + u8 byte = 0; + ENetBuffer buf; + buf.data = &byte; + buf.dataLength = 1; + enet_socket_send(host->socket, &address, &buf, 1); +} + +} -- cgit v1.2.3 From e0ef8fc03f1fafc801ca5d857347f9fa1ea58881 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 14 Mar 2015 15:19:18 +0100 Subject: NetPlay: Make the enet interrupts work Otherwise, it would work but any async sending would be delayed by 4ms or wait until the next packet was received. Also increase the client timeout to 250ms, since enet_host_service is now really interrupted. --- Source/Core/Common/ENetUtil.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Source/Core/Common/ENetUtil.cpp') diff --git a/Source/Core/Common/ENetUtil.cpp b/Source/Core/Common/ENetUtil.cpp index 7269893f90..ae5b19b2c3 100644 --- a/Source/Core/Common/ENetUtil.cpp +++ b/Source/Core/Common/ENetUtil.cpp @@ -25,4 +25,16 @@ void WakeupThread(ENetHost* host) enet_socket_send(host->socket, &address, &buf, 1); } +int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event) +{ + // wakeup packet received + if (host->receivedDataLength == 1 && host->receivedData[0] == 0) + { + event->type = (ENetEventType) 42; + return 1; + } + return 0; +} + + } -- cgit v1.2.3