Allow usbgecko to try a range of ports, such that multiple dolphin instances will setup their servers on consecutive ports starting at 55020.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6877 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
b1c6f959d9
commit
afebc0d1d3
|
@ -488,14 +488,18 @@ void SocketTCP::Create(SocketHelper::SocketType Descriptor)
|
||||||
// Setup default options
|
// Setup default options
|
||||||
if (IsValid())
|
if (IsValid())
|
||||||
{
|
{
|
||||||
|
/* We must disable this in order to detect if ports are being used by other apps, or
|
||||||
|
other instances of dolphin. This is also disabled in SFML 2.0, see
|
||||||
|
http://www.sfml-dev.org/forum/viewtopic.php?t=3388
|
||||||
// To avoid the "Address already in use" error message when trying to bind to the same port
|
// To avoid the "Address already in use" error message when trying to bind to the same port
|
||||||
int Yes = 1;
|
|
||||||
if (setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&Yes), sizeof(Yes)) == -1)
|
if (setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&Yes), sizeof(Yes)) == -1)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to set socket option \"SO_REUSEADDR\" ; "
|
std::cerr << "Failed to set socket option \"SO_REUSEADDR\" ; "
|
||||||
<< "binding to a same port may fail if too fast" << std::endl;
|
<< "binding to a same port may fail if too fast" << std::endl;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int Yes = 1;
|
||||||
// Disable the Nagle algorithm (ie. removes buffering of TCP packets)
|
// Disable the Nagle algorithm (ie. removes buffering of TCP packets)
|
||||||
if (setsockopt(mySocket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&Yes), sizeof(Yes)) == -1)
|
if (setsockopt(mySocket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&Yes), sizeof(Yes)) == -1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "EXI_Device.h"
|
#include "EXI_Device.h"
|
||||||
#include "EXI_DeviceGecko.h"
|
#include "EXI_DeviceGecko.h"
|
||||||
|
#include "..\Core.h"
|
||||||
|
|
||||||
THREAD_RETURN ClientThreadFunc(void *arg)
|
THREAD_RETURN ClientThreadFunc(void *arg)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +25,7 @@ THREAD_RETURN ClientThreadFunc(void *arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u16 GeckoSockServer::server_port;
|
||||||
int GeckoSockServer::client_count;
|
int GeckoSockServer::client_count;
|
||||||
Common::Thread *GeckoSockServer::connectionThread = NULL;
|
Common::Thread *GeckoSockServer::connectionThread = NULL;
|
||||||
volatile bool GeckoSockServer::server_running;
|
volatile bool GeckoSockServer::server_running;
|
||||||
|
@ -57,15 +59,23 @@ GeckoSockServer::~GeckoSockServer()
|
||||||
|
|
||||||
THREAD_RETURN GeckoSockServer::GeckoConnectionWaiter(void*)
|
THREAD_RETURN GeckoSockServer::GeckoConnectionWaiter(void*)
|
||||||
{
|
{
|
||||||
server_running = true;
|
|
||||||
|
|
||||||
Common::SetCurrentThreadName("Gecko Connection Waiter");
|
Common::SetCurrentThreadName("Gecko Connection Waiter");
|
||||||
|
|
||||||
sf::SocketTCP server;
|
sf::SocketTCP server;
|
||||||
// "dolphin gecko"
|
server_port = 0xd6ec; // "dolphin gecko"
|
||||||
if (!server.Listen(0xd6ec))
|
for (int bind_tries = 0; bind_tries <= 10 && !server_running; bind_tries++)
|
||||||
|
{
|
||||||
|
if (!(server_running = server.Listen(server_port)))
|
||||||
|
server_port++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!server_running)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
Core::DisplayMessage(
|
||||||
|
StringFromFormat("USBGecko: listening on TCP port %u", server_port),
|
||||||
|
5000);
|
||||||
|
|
||||||
server.SetBlocking(false);
|
server.SetBlocking(false);
|
||||||
|
|
||||||
sf::SocketTCP new_client;
|
sf::SocketTCP new_client;
|
||||||
|
|
|
@ -46,6 +46,7 @@ private:
|
||||||
// Only ever one server thread
|
// Only ever one server thread
|
||||||
static THREAD_RETURN GeckoConnectionWaiter(void*);
|
static THREAD_RETURN GeckoConnectionWaiter(void*);
|
||||||
|
|
||||||
|
static u16 server_port;
|
||||||
static volatile bool server_running;
|
static volatile bool server_running;
|
||||||
static Common::Thread *connectionThread;
|
static Common::Thread *connectionThread;
|
||||||
static std::queue<sf::SocketTCP> waiting_socks;
|
static std::queue<sf::SocketTCP> waiting_socks;
|
||||||
|
|
Loading…
Reference in New Issue