-
Notifications
You must be signed in to change notification settings - Fork 2
/
PipeProxy.cs
59 lines (52 loc) · 1.73 KB
/
PipeProxy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.IO.Pipes;
namespace KeePassNatMsgProxy
{
public class PipeProxy : ProxyBase
{
private const int ConnectTimeout = 5000;
private NamedPipeClientStream _client;
protected override bool IsClientConnected => _client.IsConnected;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<optimization>")]
protected override int ClientRead(byte[] buffer, int offset, int length)
{
try
{
return _client.Read(buffer, offset, length);
}
catch (Exception)
{
return 0;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<optimization>")]
protected override void ClientWrite(byte[] data)
{
try
{
_client.Write(data, 0, data.Length);
}
catch (Exception)
{
return;
}
}
protected override void Close()
{
_client.Close();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<optimization>")]
protected override void Connect()
{
try
{
_client = new NamedPipeClientStream(".", $"keepassxc\\{Environment.UserName}\\{ProxyName}", PipeDirection.InOut, PipeOptions.Asynchronous);
_client.Connect(ConnectTimeout);
}
catch (Exception)
{
return;
}
}
}
}