public bool SendInternalBuffer() { NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short)29, "msg", 1); if (!this.m_IsReliable || this.m_PendingPackets.Count <= 0) { return(this.m_CurrentPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId)); } while (this.m_PendingPackets.Count > 0) { ChannelPacket packet = this.m_PendingPackets.Dequeue(); if (!packet.SendToTransport(this.m_Connection, (int)this.m_ChannelId)) { this.m_PendingPackets.Enqueue(packet); break; } --ChannelBuffer.pendingPacketCount; ChannelBuffer.FreePacket(packet); if (this.m_IsBroken && this.m_PendingPackets.Count < this.m_MaxPendingPacketCount / 2) { if (LogFilter.logWarn) { Debug.LogWarning((object)"ChannelBuffer recovered from overflow but data was lost."); } this.m_IsBroken = false; } } return(true); }
static int s_MaxPacketStats = 255;//the same as maximum message types #endif public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology) { m_Writer = new NetworkWriter(); address = networkAddress; hostId = networkHostId; connectionId = networkConnectionId; int numChannels = hostTopology.DefaultConfig.ChannelCount; int packetSize = hostTopology.DefaultConfig.PacketSize; if ((hostTopology.DefaultConfig.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4) && (UnityEngine.Application.platform != RuntimePlatform.PSP2)) { throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform"); } m_Channels = new ChannelBuffer[numChannels]; for (int i = 0; i < numChannels; i++) { var qos = hostTopology.DefaultConfig.Channels[i]; int actualPacketSize = packetSize; if (qos.QOS == QosType.ReliableFragmented || qos.QOS == QosType.UnreliableFragmented) { actualPacketSize = hostTopology.DefaultConfig.FragmentSize * 128; } m_Channels[i] = new ChannelBuffer(this, actualPacketSize, (byte)i, IsReliableQoS(qos.QOS), IsSequencedQoS(qos.QOS)); } }
public bool SendInternalBuffer() { bool result; if (this.m_IsReliable && this.m_PendingPackets.Count > 0) { while (this.m_PendingPackets.Count > 0) { ChannelPacket channelPacket = this.m_PendingPackets.Dequeue(); if (!channelPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId)) { this.m_PendingPackets.Enqueue(channelPacket); break; } ChannelBuffer.pendingPacketCount--; ChannelBuffer.FreePacket(channelPacket); if (this.m_IsBroken && this.m_PendingPackets.Count < this.m_MaxPendingPacketCount / 2) { if (LogFilter.logWarn) { Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost."); } this.m_IsBroken = false; } } result = true; } else { result = this.m_CurrentPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId); } return(result); }
public bool SendInternalBuffer() { if (this.m_IsReliable && this.m_PendingPackets.Count > 0) { while (this.m_PendingPackets.Count > 0) { ChannelPacket packet = this.m_PendingPackets[0]; if (!packet.SendToTransport(this.m_Connection, (int)this.m_ChannelId)) { break; } ChannelBuffer.pendingPacketCount--; this.m_PendingPackets.RemoveAt(0); ChannelBuffer.FreePacket(packet); if (this.m_IsBroken && this.m_PendingPackets.Count < this.m_MaxPendingPacketCount / 2) { if (LogFilter.logWarn) { Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost."); } this.m_IsBroken = false; } } return(true); } return(this.m_CurrentPacket.SendToTransport(this.m_Connection, (int)this.m_ChannelId)); }
public virtual void GetStatsIn(out int numMsgs, out int numBytes) { numMsgs = 0; numBytes = 0; for (int i = 0; i < this.m_Channels.Length; i++) { ChannelBuffer buffer = this.m_Channels[i]; numMsgs += buffer.numMsgsIn; numBytes += buffer.numBytesIn; } }
public void SetMaxDelay(float seconds) { if (this.m_Channels == null) { return; } ChannelBuffer[] channels = this.m_Channels; for (int i = 0; i < channels.Length; i++) { ChannelBuffer channelBuffer = channels[i]; channelBuffer.maxDelay = seconds; } }
public void FlushChannels() { if (this.m_Channels == null) { return; } ChannelBuffer[] channels = this.m_Channels; for (int i = 0; i < channels.Length; i++) { ChannelBuffer channelBuffer = channels[i]; channelBuffer.CheckInternalBuffer(); } }
internal void HandleFragment(NetworkReader reader, int channelId) { if ((channelId >= 0) && (channelId < this.m_Channels.Length)) { ChannelBuffer buffer = this.m_Channels[channelId]; if (buffer.HandleFragment(reader)) { NetworkReader reader2 = new NetworkReader(buffer.fragmentBuffer.AsArraySegment().Array); reader2.ReadInt16(); short msgType = reader2.ReadInt16(); this.InvokeHandler(msgType, reader2, channelId); } } }
internal void HandleFragment(NetworkReader reader, int channelId) { if (channelId >= 0 && channelId < this.m_Channels.Length) { ChannelBuffer channelBuffer = this.m_Channels[channelId]; if (channelBuffer.HandleFragment(reader)) { NetworkReader networkReader = new NetworkReader(channelBuffer.fragmentBuffer.AsArraySegment().Array); networkReader.ReadInt16(); short msgType = networkReader.ReadInt16(); this.InvokeHandler(msgType, networkReader, channelId); } } }
public virtual void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond) { numMsgs = 0; numBufferedMsgs = 0; numBytes = 0; lastBufferedPerSecond = 0; for (int i = 0; i < this.m_Channels.Length; i++) { ChannelBuffer buffer = this.m_Channels[i]; numMsgs += buffer.numMsgsOut; numBufferedMsgs += buffer.numBufferedMsgsOut; numBytes += buffer.numBytesOut; lastBufferedPerSecond += buffer.lastBufferedPerSecond; } }
public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId, HostTopology hostTopology) { m_Writer = new NetworkWriter(); address = networkAddress; hostId = networkHostId; connectionId = networkConnectionId; int channelCount = hostTopology.DefaultConfig.ChannelCount; int packetSize = hostTopology.DefaultConfig.PacketSize; m_Channels = new ChannelBuffer[channelCount]; for (int i = 0; i < channelCount; i++) { ChannelQOS channelQOS = hostTopology.DefaultConfig.Channels[i]; int bufferSize = packetSize; if (channelQOS.QOS == QosType.ReliableFragmented || channelQOS.QOS == QosType.UnreliableFragmented) { bufferSize = hostTopology.DefaultConfig.FragmentSize * 128; } m_Channels[i] = new ChannelBuffer(this, bufferSize, (byte)i, IsReliableQoS(channelQOS.QOS)); } }