Gwupe.Communication.P2P.RUDP.Connector.ProxyTcpConnection.TcpReaderToTransportSocketWriter C# (CSharp) Method

TcpReaderToTransportSocketWriter() private method

private TcpReaderToTransportSocketWriter ( ) : void
return void
        private void TcpReaderToTransportSocketWriter()
        {
            try
            {
                int read = -1;
                while (read != 0)
                {
                    byte[] tmpRead = new byte[16384];
                    try
                    {
                        read = _tcpClient.GetStream().Read(tmpRead, 0, tmpRead.Length);
                    }
                    catch (Exception e)
                    {
                        Logger.Debug("Reading from the tcp stream caused an exception, most likely its gone.", e);
                        read = 0;
                    }
                    if (read > 0)
                    {
            #if(DEBUG)
                        Logger.Debug("Read " + read + " bytes from tcp socket, writing to transportManager [md5=" + Util.getSingleton().getMD5Hash(tmpRead, 0, read) + "]");
            #endif
                        try
                        {
                            if (!SendDataToTransportSocket(tmpRead, read))
                            {
                                Logger.Debug("Failed to read from the transport socket, closing.");
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Error("Sending to transport failed, shutting down ProxyTransportWriter", e);
                            break;
                        }
                    }
                    else
                    {
                        Logger.Info("Proxied tcp stream has closed");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Connection has failed : " + ex.Message, ex);
            }
            finally
            {
                try
                {
                    Close();
                }
                catch (Exception e)
                {
                    Logger.Error("Error while closing ProxyConnection : " + e.Message, e);
                }
            }
        }