From 82282f0978e93c686cfa2eb1838aaaaae8e5f71d Mon Sep 17 00:00:00 2001 From: bgk Date: Sun, 23 Sep 2012 12:07:02 +0000 Subject: [PATCH] LINK: Don't silently fail when unable to connect to Dolphin git-svn-id: https://svn.code.sf.net/p/vbam/code/branches/bgk-link@1138 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/gba/GBALink.cpp | 20 ++++++++++++++------ src/gba/GBASockClient.cpp | 14 +++++++++----- src/gba/GBASockClient.h | 3 ++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/gba/GBALink.cpp b/src/gba/GBALink.cpp index 5ea951b1..9dce96d3 100644 --- a/src/gba/GBALink.cpp +++ b/src/gba/GBALink.cpp @@ -451,12 +451,20 @@ void StartGPLink(u16 value) } } -static void JoyBusConnect() +static ConnectionState JoyBusConnect() { delete dol; dol = NULL; - dol = new GBASockClient(joybusHostAddr); + dol = new GBASockClient(); + bool connected = dol->Connect(joybusHostAddr); + + if (connected) { + return LINK_OK; + } else { + systemMessage(0, N_("Error, could not connect to Dolphin")); + return LINK_ERROR; + } } static void JoyBusShutdown() @@ -1171,10 +1179,10 @@ ConnectionState InitLink(LinkMode mode) gba_connection_state = LINK_OK; - if (mode == LINK_GAMECUBE_DOLPHIN) { - JoyBusConnect(); - } else if (mode == LINK_CABLE_IPC || mode == LINK_RFU_IPC) { - gba_connection_state = InitIPC(); + if (mode == LINK_GAMECUBE_DOLPHIN) { + gba_connection_state = JoyBusConnect(); + } else if (mode == LINK_CABLE_IPC || mode == LINK_RFU_IPC) { + gba_connection_state = InitIPC(); } else if (mode == LINK_CABLE_SOCKET) { linkid = 0; diff --git a/src/gba/GBASockClient.cpp b/src/gba/GBASockClient.cpp index 05843f56..cafd02b7 100644 --- a/src/gba/GBASockClient.cpp +++ b/src/gba/GBASockClient.cpp @@ -4,15 +4,19 @@ // Currently only for Joybus communications -GBASockClient::GBASockClient(sf::IPAddress _server_addr) +GBASockClient::GBASockClient() { - if (!_server_addr.IsValid()) - server_addr = sf::IPAddress::LocalHost; - else + server_addr = sf::IPAddress::LocalHost; +} + +bool GBASockClient::Connect(sf::IPAddress _server_addr) { + if (_server_addr.IsValid()) server_addr = _server_addr; - client.Connect(0xd6ba, server_addr); + sf::Socket::Status result = client.Connect(0xd6ba, server_addr); //client.SetBlocking(false); + + return result == sf::Socket::Done; } GBASockClient::~GBASockClient() diff --git a/src/gba/GBASockClient.h b/src/gba/GBASockClient.h index a90cdfa0..7486e8f8 100644 --- a/src/gba/GBASockClient.h +++ b/src/gba/GBASockClient.h @@ -6,9 +6,10 @@ class GBASockClient { public: - GBASockClient(sf::IPAddress server_addr); + GBASockClient(); ~GBASockClient(); + bool Connect(sf::IPAddress server_addr); void Send(std::vector data); char ReceiveCmd(char* data_in);