forked from bonesoul/uhttpsharp
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathTcpClientAdapter.cs
More file actions
54 lines (43 loc) · 1.35 KB
/
TcpClientAdapter.cs
File metadata and controls
54 lines (43 loc) · 1.35 KB
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
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace uhttpsharp.Clients
{
public class TcpClientAdapter : IClient
{
private readonly TcpClient _client;
private readonly NetworkStream _stream;
public TcpClientAdapter(TcpClient client)
{
_client = client;
_stream = _client.GetStream();
// The next lines are commented out because they caused exceptions,
// They have been added because .net doesn't allow me to wait for data (ReadAsyncBlock).
// Instead, I've added Task.Delay in MyStreamReader.ReadBuffer when
// Read returns without data.
// See https://github.com/Code-Sharp/uHttpSharp/issues/14
// Read Timeout of one second.
// _stream.ReadTimeout = 1000;
}
public Stream Stream
{
get { return _stream; }
}
public bool Connected
{
get { return _client.Connected; }
}
public void Close()
{
_client.Close();
}
public EndPoint RemoteEndPoint
{
get { return _client.Client.RemoteEndPoint; }
}
public Task InitializeStream() {
return Task.Factory.GetCompleted();
}
}
}