From 04b7647bfbcf5418c430f2cc0604df000c7b4709 Mon Sep 17 00:00:00 2001 From: lidgren Date: Tue, 10 Aug 2010 11:21:56 +0000 Subject: [PATCH] Logging error instead of throwing exception on network thread in RELEASE Removed superflous break Added new keyword to ReadByte() - not optimal, but it will have to do for now --- Lidgren.Network/NetConnection.cs | 1 - Lidgren.Network/NetIncomingMessage.Read.cs | 3 +- Lidgren.Network/NetPeer.Internal.cs | 34 ++++++++++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Lidgren.Network/NetConnection.cs b/Lidgren.Network/NetConnection.cs index 34bf55f..dc0b2e7 100644 --- a/Lidgren.Network/NetConnection.cs +++ b/Lidgren.Network/NetConnection.cs @@ -639,7 +639,6 @@ namespace Lidgren.Network case NetDeliveryMethod.Unknown: default: throw new NetException("Bad delivery method!"); - break; } if (m_owner == null) diff --git a/Lidgren.Network/NetIncomingMessage.Read.cs b/Lidgren.Network/NetIncomingMessage.Read.cs index fb3c8a0..297f8a5 100644 --- a/Lidgren.Network/NetIncomingMessage.Read.cs +++ b/Lidgren.Network/NetIncomingMessage.Read.cs @@ -75,7 +75,7 @@ namespace Lidgren.Network // // 8 bit // - public byte ReadByte() + public new byte ReadByte() { NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError); byte retval = NetBitWriter.ReadByte(m_data, 8, m_readPosition); @@ -83,6 +83,7 @@ namespace Lidgren.Network return retval; } + [CLSCompliant(false)] public sbyte ReadSByte() { diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index 59a0b6c..6aa4e97 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -124,7 +124,7 @@ namespace Lidgren.Network int first = (pa == null ? this.GetHashCode() : pa.GetHashCode()); int second = boundEp.GetHashCode(); - + byte[] raw = new byte[8]; raw[0] = (byte)first; raw[1] = (byte)(first << 8); @@ -139,21 +139,45 @@ namespace Lidgren.Network m_receiveBuffer = new byte[m_configuration.ReceiveBufferSize]; m_sendBuffer = new byte[m_configuration.SendBufferSize]; - LogVerbose("Initialization done"); + throw new Exception("borak!"); // only set Running if everything succeeds m_status = NetPeerStatus.Running; + + LogVerbose("Initialization done"); } +#if DEBUG + catch(Exception ex) + { + throw; + } +#else catch (SocketException sex) { + // catastrophic failure; we can't know what's been initialized, try to back out + m_status = NetPeerStatus.NotRunning; + if (sex.SocketErrorCode == SocketError.AddressAlreadyInUse) - throw new NetException("Failed to bind to port " + (iep == null ? "Null" : iep.ToString()) + " - Address already in use!", sex); - throw; + LogError("Failed to bind to port " + (iep == null ? "Null" : iep.ToString()) + " - Address already in use!"); + else + LogError(sex.Message); + LogError("Lidgren could not initialize properly; please call Start() again"); + + // exit thread + return; } catch (Exception ex) { - throw new NetException("Failed to bind to " + (iep == null ? "Null" : iep.ToString()), ex); + // catastrophic failure; we can't know what's been initialized, try to back out + m_status = NetPeerStatus.NotRunning; + + LogError(ex.Message); + LogError("Lidgren could not initialize properly; please call Start() again"); + + // exit thread + return; } +#endif } //