forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelPacket.cs
More file actions
71 lines (63 loc) · 2.17 KB
/
ChannelPacket.cs
File metadata and controls
71 lines (63 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Decompiled with JetBrains decompiler
// Type: UnityEngine.Networking.ChannelPacket
// Assembly: UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8B34E19C-EF53-416E-AE36-35C45BAFD2DE
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEngine.Networking.dll
using System;
using UnityEditor;
namespace UnityEngine.Networking
{
internal struct ChannelPacket
{
private int m_Position;
private byte[] m_Buffer;
private bool m_IsReliable;
public ChannelPacket(int packetSize, bool isReliable)
{
this.m_Position = 0;
this.m_Buffer = new byte[packetSize];
this.m_IsReliable = isReliable;
}
public void Reset()
{
this.m_Position = 0;
}
public bool IsEmpty()
{
return this.m_Position == 0;
}
public void Write(byte[] bytes, int numBytes)
{
Array.Copy((Array) bytes, 0, (Array) this.m_Buffer, this.m_Position, numBytes);
this.m_Position += numBytes;
}
public bool HasSpace(int numBytes)
{
return this.m_Position + numBytes <= this.m_Buffer.Length;
}
public bool SendToTransport(NetworkConnection conn, int channelId)
{
bool flag = true;
byte error;
if (!conn.TransportSend(this.m_Buffer, (int) (ushort) this.m_Position, channelId, out error) && (!this.m_IsReliable || (int) error != 4))
{
if (LogFilter.logError)
Debug.LogError((object) ("Failed to send internal buffer channel:" + (object) channelId + " bytesToSend:" + (object) this.m_Position));
flag = false;
}
if ((int) error != 0)
{
if (this.m_IsReliable && (int) error == 4)
{
NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short) 30, "msg", 1);
return false;
}
if (LogFilter.logError)
Debug.LogError((object) ("Send Error: " + (object) error + " channel:" + (object) channelId + " bytesToSend:" + (object) this.m_Position));
flag = false;
}
this.m_Position = 0;
return flag;
}
}
}