Skip to content

Commit 4566032

Browse files
committed
fix: UNET transport task not completing
1 parent 992cc49 commit 4566032

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

MLAPI/Transports/UNET/UnetTransport.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public class UnetTransport : Transport
1919
public int ServerWebsocketListenPort = 8887;
2020
public bool SupportWebsocket = false;
2121
public List<UnetChannel> Channels = new List<UnetChannel>();
22-
22+
2323
// Relay
2424
public bool UseMLAPIRelay = false;
2525
public string MLAPIRelayAddress = "184.72.104.138";
2626
public int MLAPIRelayPort = 8888;
27-
27+
2828
// Runtime / state
2929
private byte[] messageBuffer;
3030
private WeakReference temporaryBufferReference;
@@ -38,11 +38,11 @@ public class UnetTransport : Transport
3838
private SocketTask connectTask;
3939

4040
public override ulong ServerClientId => GetMLAPIClientId(0, 0, true);
41-
41+
4242
public override void Send(ulong clientId, ArraySegment<byte> data, string channelName)
43-
{
43+
{
4444
GetUnetConnectionDetails(clientId, out byte hostId, out ushort connectionId);
45-
45+
4646
int channelId = channelNameToId[channelName];
4747

4848
byte[] buffer;
@@ -67,7 +67,7 @@ public override void Send(ulong clientId, ArraySegment<byte> data, string channe
6767
temporaryBufferReference = new WeakReference(buffer);
6868
}
6969
}
70-
70+
7171
Buffer.BlockCopy(data.Array, data.Offset, buffer, 0, data.Count);
7272
}
7373
else
@@ -81,17 +81,17 @@ public override void Send(ulong clientId, ArraySegment<byte> data, string channe
8181
public override NetEventType PollEvent(out ulong clientId, out string channelName, out ArraySegment<byte> payload, out float receiveTime)
8282
{
8383
NetworkEventType eventType = RelayTransport.Receive(out int hostId, out int connectionId, out int channelId, messageBuffer, messageBuffer.Length, out int receivedSize, out byte error);
84-
84+
8585
clientId = GetMLAPIClientId((byte) hostId, (ushort) connectionId, false);
8686

8787
receiveTime = UnityEngine.Time.realtimeSinceStartup;
8888

8989
NetworkError networkError = (NetworkError) error;
90-
90+
9191
if (networkError == NetworkError.MessageToLong)
9292
{
9393
byte[] tempBuffer;
94-
94+
9595
if (temporaryBufferReference != null && temporaryBufferReference.IsAlive && ((byte[]) temporaryBufferReference.Target).Length >= receivedSize)
9696
{
9797
tempBuffer = (byte[])temporaryBufferReference.Target;
@@ -101,7 +101,7 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam
101101
tempBuffer = new byte[receivedSize];
102102
temporaryBufferReference = new WeakReference(tempBuffer);
103103
}
104-
104+
105105
eventType = RelayTransport.Receive(out hostId, out connectionId, out channelId, tempBuffer, tempBuffer.Length, out receivedSize, out error);
106106
payload = new ArraySegment<byte>(tempBuffer, 0, receivedSize);
107107
}
@@ -162,7 +162,7 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam
162162
case NetworkEventType.BroadcastEvent:
163163
return NetEventType.Nothing;
164164
}
165-
165+
166166
return NetEventType.Nothing;
167167
}
168168

@@ -190,7 +190,7 @@ public override SocketTasks StartClient()
190190
task.Success = false;
191191
task.TransportCode = error;
192192
task.SocketError = System.Net.Sockets.SocketError.SocketError;
193-
task.IsDone = false;
193+
task.IsDone = true;
194194
break;
195195
}
196196

@@ -200,7 +200,7 @@ public override SocketTasks StartClient()
200200
public override SocketTasks StartServer()
201201
{
202202
HostTopology topology = new HostTopology(GetConfig(), MaxConnections);
203-
203+
204204
if (SupportWebsocket)
205205
{
206206
if (!UseMLAPIRelay)
@@ -211,9 +211,9 @@ public override SocketTasks StartServer()
211211
{
212212
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Cannot create websocket host when using MLAPI relay");
213213
}
214-
214+
215215
}
216-
216+
217217
int normalHostId = RelayTransport.AddHost(topology, ServerListenPort, true);
218218

219219
return SocketTask.Done.AsTasks();
@@ -255,12 +255,12 @@ public override void Shutdown()
255255
public override void Init()
256256
{
257257
UpdateRelay();
258-
258+
259259
messageBuffer = new byte[MessageBufferSize];
260-
260+
261261
NetworkTransport.Init();
262262
}
263-
263+
264264
public ulong GetMLAPIClientId(byte hostId, ushort connectionId, bool isServer)
265265
{
266266
if (isServer)
@@ -290,26 +290,26 @@ public void GetUnetConnectionDetails(ulong clientId, out byte hostId, out ushort
290290
public ConnectionConfig GetConfig()
291291
{
292292
ConnectionConfig config = new ConnectionConfig();
293-
293+
294294
for (int i = 0; i < MLAPI_CHANNELS.Length; i++)
295295
{
296296
int channelId = AddMLAPIChannel(MLAPI_CHANNELS[i].Type, config);
297-
297+
298298
channelIdToName.Add(channelId, MLAPI_CHANNELS[i].Name);
299299
channelNameToId.Add(MLAPI_CHANNELS[i].Name, channelId);
300300
}
301301

302302
for (int i = 0; i < Channels.Count; i++)
303303
{
304304
int channelId = AddUNETChannel(Channels[i].Type, config);
305-
305+
306306
channelIdToName.Add(channelId, Channels[i].Name);
307307
channelNameToId.Add(Channels[i].Name, channelId);
308308
}
309309

310310
return config;
311311
}
312-
312+
313313
public int AddMLAPIChannel(ChannelType type, ConnectionConfig config)
314314
{
315315
switch (type)
@@ -328,7 +328,7 @@ public int AddMLAPIChannel(ChannelType type, ConnectionConfig config)
328328

329329
return 0;
330330
}
331-
331+
332332
public int AddUNETChannel(QosType type, ConnectionConfig config)
333333
{
334334
switch (type)
@@ -368,4 +368,4 @@ private void UpdateRelay()
368368
}
369369
}
370370
}
371-
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
371+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

0 commit comments

Comments
 (0)