//================================================================================ #endregion #region Constructor //================================================================================ public ProxyService(int listenPort, string toHost, int toPort, ILogger logger, IByPasser clientLogger = null, IByPasser targetLogger = null) { _logger = logger; _listenPort = listenPort; _toHost = toHost; _toPort = toPort; _clientLogger = clientLogger != null ? clientLogger : ByPasser.Default; _targetLogger = targetLogger != null ? targetLogger : ByPasser.Default; }
//================================================================================ private bool CopyFromStream(NetworkStream from, NetworkStream to, Action <int> bytesRead, IByPasser logger) { try { if (from.CanRead && to.CanWrite) { byte[] myReadBuffer = new byte[1000024]; int numberOfBytesRead = 0; do { numberOfBytesRead = from.Read(myReadBuffer, 0, myReadBuffer.Length); if (_latency != 0) { Thread.Sleep(_latency); } if (numberOfBytesRead != 0) { numberOfBytesRead = logger.Write(to, myReadBuffer, 0, numberOfBytesRead); bytesRead(numberOfBytesRead); } else { return(false); } }while (from.DataAvailable); to.Flush(); return(true); } else { return(false); } } catch { return(false); } }
public LoggingBypasser(Action <byte[], int, int> logger, IByPasser piggyback = null) { _piggyback = piggyback != null ? piggyback : ByPasser.Default; _logger = logger; }
public HostReplaceBypasser(string realHost, IByPasser piggyback = null) { _realHost = realHost; _piggyback = piggyback != null ? piggyback : ByPasser.Default; }
//================================================================================ private bool CopyFromStream(NetworkStream from, NetworkStream to, Action<int> bytesRead, IByPasser logger) { try { if (from.CanRead && to.CanWrite) { byte[] myReadBuffer = new byte[1000024]; int numberOfBytesRead = 0; do { numberOfBytesRead = from.Read(myReadBuffer, 0, myReadBuffer.Length); if (_latency != 0) Thread.Sleep(_latency); if (numberOfBytesRead != 0) { numberOfBytesRead = logger.Write(to, myReadBuffer, 0, numberOfBytesRead); bytesRead(numberOfBytesRead); } else { return false; } } while (from.DataAvailable); to.Flush(); return true; } else { return false; } } catch { return false; } }
public LoggingBypasser(Action<byte[], int, int> logger, IByPasser piggyback = null) { _piggyback = piggyback != null ? piggyback : ByPasser.Default; _logger = logger; }