blob: 1e865a8515f89891cd49a80e8ebe8fc45e13718e (
plain)
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
|
using Hazel.Udp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hazel.UnitTests
{
internal class UdpConnectionTestHarness : UdpConnection
{
public List<MessageReader> BytesSent = new List<MessageReader>();
public UdpConnectionTestHarness() : base(new TestLogger())
{
}
public ushort ReliableReceiveLast => this.reliableReceiveLast;
public override void Connect(byte[] bytes = null, int timeout = 5000)
{
this.State = ConnectionState.Connected;
}
public override void ConnectAsync(byte[] bytes = null)
{
this.State = ConnectionState.Connected;
}
protected override bool SendDisconnect(MessageWriter writer)
{
lock (this)
{
if (this.State != ConnectionState.Connected)
{
return false;
}
this.State = ConnectionState.NotConnected;
}
return true;
}
protected override void WriteBytesToConnection(byte[] bytes, int length)
{
this.BytesSent.Add(MessageReader.Get(bytes));
}
public void Test_Receive(MessageWriter msg)
{
byte[] buffer = new byte[msg.Length];
Buffer.BlockCopy(msg.Buffer, 0, buffer, 0, msg.Length);
var data = MessageReader.Get(buffer);
this.HandleReceive(data, data.Length);
}
}
}
|