This repository was archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathDummyTcpSocket.cs
More file actions
97 lines (81 loc) · 2.55 KB
/
DummyTcpSocket.cs
File metadata and controls
97 lines (81 loc) · 2.55 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
namespace SharpAdbClient.Tests
{
internal class DummyTcpSocket : ITcpSocket
{
/// <summary>
/// The stream from which the <see cref="DummyTcpSocket"/> reads.
/// </summary>
public MemoryStream InputStream
{ get; set; } = new MemoryStream();
/// <summary>
/// The stream to which the <see cref="DummyTcpSocket"/> writes.
/// </summary>
public MemoryStream OutputStream
{ get; set; } = new MemoryStream();
public bool Connected
{ get; set; } = true;
public int ReceiveBufferSize
{ get; set; } = 1024;
public int ReceiveTimeout
{ get; set; } = -1;
public void Close()
{
this.Connected = false;
}
public void Connect(EndPoint endPoint)
{
this.Connected = true;
}
public Task ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
{
Connect(endPoint);
return Task.CompletedTask;
}
public void Reconnect()
{
throw new NotImplementedException();
}
public Task ReconnectAsync(CancellationToken cancellationToken)
{
Reconnect();
return Task.CompletedTask;
}
public void Dispose()
{
this.Connected = false;
}
public Stream GetStream()
{
return this.OutputStream;
}
public int Receive(byte[] buffer, int size, SocketFlags socketFlags)
{
return this.InputStream.Read(buffer, 0, size);
}
public Task<int> ReceiveAsync(byte[] buffer, int offset, int size, SocketFlags socketFlags, CancellationToken cancellationToken)
{
int value = this.InputStream.Read(buffer, offset, size);
return Task.FromResult(value);
}
public int Send(byte[] buffer, int offset, int size, SocketFlags socketFlags)
{
this.OutputStream.Write(buffer, offset, size);
return size;
}
public Task<int> SendAsync(byte[] buffer, int offset, int size, SocketFlags socketFlags, CancellationToken cancellationToken)
{
this.OutputStream.Write(buffer, offset, size);
return Task.FromResult(size);
}
public byte[] GetBytesSent()
{
return this.OutputStream.ToArray();
}
}
}