From ff7ea85ab92aa9434f7b83536f2519c8328430ca Mon Sep 17 00:00:00 2001 From: JamJar00 Date: Sat, 22 Oct 2016 01:02:39 +0100 Subject: [PATCH] Fixed bug on connection failure --- Hazel/Tcp/TcpConnection.cs | 19 +++++++++++++++++-- Hazel/Tcp/TcpConnectionListener.cs | 10 +--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Hazel/Tcp/TcpConnection.cs b/Hazel/Tcp/TcpConnection.cs index e4f8f97..6ce67f3 100644 --- a/Hazel/Tcp/TcpConnection.cs +++ b/Hazel/Tcp/TcpConnection.cs @@ -175,7 +175,7 @@ namespace Hazel.Tcp } catch (SocketException e) { - HandleDisconnect(new HazelException("A Socket exception occured while initiating a body receive operation.", e)); + HandleDisconnect(new HazelException("A Socket exception occured while initiating a header receive operation.", e)); } Statistics.LogReceive(bytes.Length, bytes.Length + 4); @@ -184,10 +184,25 @@ namespace Hazel.Tcp InvokeDataReceived(bytes, SendOption.FragmentedReliable); } + /// + /// Starts this connection receiving data. + /// + internal void StartReceiving() + { + try + { + StartWaitingForHeader(); + } + catch (SocketException e) + { + HandleDisconnect(new HazelException("A Socket exception occured while initiating the first receive operation.", e)); + } + } + /// /// Starts this connections waiting for the header. /// - internal void StartWaitingForHeader() + void StartWaitingForHeader() { StartWaitingForBytes(4, HeaderReadCallback); } diff --git a/Hazel/Tcp/TcpConnectionListener.cs b/Hazel/Tcp/TcpConnectionListener.cs index 9e174b9..2419b1b 100644 --- a/Hazel/Tcp/TcpConnectionListener.cs +++ b/Hazel/Tcp/TcpConnectionListener.cs @@ -101,15 +101,7 @@ namespace Hazel.Tcp //Invoke InvokeNewConnection(tcpConnection); - try - { - tcpConnection.StartWaitingForHeader(); - } - catch (SocketException) - { - //Receive operation couldn't be started, there's nothing we can do to save it - return; - } + tcpConnection.StartReceiving(); } } -- 2.39.5