Skip to content

Commit

Permalink
Fix BlueBox crash on HashLink
Browse files Browse the repository at this point in the history
Prevent HashLink from crashing when attempting to connect through BlueBox to a closed socket.
  • Loading branch information
DigiEggz committed Aug 11, 2023
1 parent 1bbf696 commit 4bd2534
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion com/smartfoxserver/v2/SmartFox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2214,9 +2214,10 @@ class SmartFox extends EventDispatcher

private function handleConnectionProblem(evt:BitSwarmEvent):Void
{
// Socket failed, attempt using the BBox
// Socket failed, attempt using BlueBox
if(_bitSwarm.connectionMode==ConnectionMode.SOCKET && _useBlueBox)
{
_bitSwarm.disconnect();
_bitSwarm.forceBlueBox(true);
var bbPort:Int = config != null ? config.httpPort:DEFAULT_HTTP_PORT;

Expand Down
12 changes: 7 additions & 5 deletions com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class BitSwarmClient extends EventDispatcher

public function forceBlueBox(value:Bool):Void
{
if(!connected)
if(!connected || _attemptingReconnection)
_useBlueBox = value;
else
throw new IllegalOperationError("You can't change the BlueBox mode while the connection is running");
Expand Down Expand Up @@ -627,8 +627,8 @@ class BitSwarmClient extends EventDispatcher
{
processIOError(evt.toString());

// Android _socket not receiving Event.CLOSE; manually disconnect on I/O error
#if android
// Android and HashLink _socket not receiving Event.CLOSE; manually disconnect on I/O error
#if (android || hl)
disconnect();
#end
}
Expand Down Expand Up @@ -674,8 +674,10 @@ class BitSwarmClient extends EventDispatcher
trace("## BlueBox Dynamic:" + evt.params.message);
var event:BitSwarmEvent = new BitSwarmEvent(BitSwarmEvent.IO_ERROR);
event.params = { message:evt.params.message };

dispatchEvent(event);


//dispatchEvent(event);
onBBDisconnect(evt);
}

function get_connectionPort():Int
Expand Down

0 comments on commit 4bd2534

Please sign in to comment.