Skip to content

Commit

Permalink
don't read/write header (size) data
Browse files Browse the repository at this point in the history
  • Loading branch information
smorks committed Nov 30, 2017
1 parent 74fb3c6 commit da741d8
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static void Main(string[] args)
proxy.Run();
}

private const int BufferSize = 1024*1024;
private const string PipeName = "KeePassHttp";
private const int ConnectTimeout = 5000;
private NamedPipeClientStream _client;
Expand Down Expand Up @@ -65,27 +66,22 @@ private void ClientWrite(byte[] data)
{
if (_active && _client.IsConnected)
{
var hdr = BitConverter.GetBytes(data.Length);
_client.Write(hdr, 0, hdr.Length);
_client.Write(data, 0, data.Length);
_client.Flush();
}
}

private void ClientReadThread()
{
while (_active && _client.IsConnected)
{
var hdr = new byte[4];
var bytes = _client.Read(hdr, 0, hdr.Length);
if (bytes == hdr.Length)
var buffer = new byte[BufferSize];
var bytes = _client.Read(buffer, 0, buffer.Length);
if (bytes > 0)
{
var dataLen = BitConverter.ToInt32(hdr, 0);
var data = new byte[dataLen];
bytes = _client.Read(data, 0, data.Length);
if (bytes == dataLen)
{
ConsoleWrite(data);
}
var data = new byte[bytes];
Array.Copy(buffer, data, bytes);
ConsoleWrite(data);
}
}
}
Expand Down

0 comments on commit da741d8

Please sign in to comment.