From c2096d0fb752a2fb8568061e2c64d7fdc33ddbe8 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Wed, 13 Nov 2019 14:47:18 -0600 Subject: [PATCH] Available transport is determined at connection time (#1213) * Available transport is determined at connection time * Update MultiplexTransport.cs --- .../Runtime/Transport/MultiplexTransport.cs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Assets/Mirror/Runtime/Transport/MultiplexTransport.cs b/Assets/Mirror/Runtime/Transport/MultiplexTransport.cs index 4bf2abcd7..b097362e8 100644 --- a/Assets/Mirror/Runtime/Transport/MultiplexTransport.cs +++ b/Assets/Mirror/Runtime/Transport/MultiplexTransport.cs @@ -10,6 +10,8 @@ public class MultiplexTransport : Transport { public Transport[] transports; + Transport available; + // used to partition recipients for each one of the base transports // without allocating a new list every time List[] recipientsCache; @@ -51,42 +53,39 @@ void InitClient() } } - // The client just uses the first transport available - Transport GetAvailableTransport() + public override void ClientConnect(string address) { foreach (Transport transport in transports) { if (transport.Available()) { - return transport; + available = transport; + transport.ClientConnect(address); + } } throw new Exception("No transport suitable for this platform"); } - public override void ClientConnect(string address) - { - GetAvailableTransport().ClientConnect(address); - } - public override bool ClientConnected() { - return GetAvailableTransport().ClientConnected(); + return available != null && available.ClientConnected(); } public override void ClientDisconnect() { - GetAvailableTransport().ClientDisconnect(); + if (available != null) + available.ClientDisconnect(); } public override bool ClientSend(int channelId, ArraySegment segment) { - return GetAvailableTransport().ClientSend(channelId, segment); + return available.ClientSend(channelId, segment); } public override int GetMaxPacketSize(int channelId = 0) { - return GetAvailableTransport().GetMaxPacketSize(channelId); + return available.GetMaxPacketSize(channelId); } #endregion