StateObject.cs
2.23 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
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace HslCommunication.Core.Net
{
/// <summary>
/// 网络中的异步对象
/// </summary>
internal class StateObject : StateOneBase
{
#region Constructor
/// <summary>
/// 实例化一个对象
/// </summary>
public StateObject( )
{
}
/// <summary>
/// 实例化一个对象,指定接收或是发送的数据长度
/// </summary>
/// <param name="length">数据长度</param>
public StateObject( int length )
{
DataLength = length;
Buffer = new byte[length];
}
#endregion
#region Public Member
/// <summary>
/// 唯一的一串信息
/// </summary>
public string UniqueId { get; set; }
/// <summary>
/// 网络套接字
/// </summary>
public Socket WorkSocket { get; set; }
/// <summary>
/// 是否关闭了通道
/// </summary>
public bool IsClose { get; set; }
#endregion
#region Public Method
/// <summary>
/// 清空旧的数据
/// </summary>
public void Clear( )
{
IsError = false;
IsClose = false;
AlreadyDealLength = 0;
Buffer = null;
}
#endregion
}
#if !NET35
/// <summary>
/// 携带TaskCompletionSource属性的异步对象
/// </summary>
/// <typeparam name="T">类型</typeparam>
internal class StateObjectAsync<T> : StateObject
{
#region Constructor
/// <summary>
/// 实例化一个对象
/// </summary>
public StateObjectAsync( ) : base( )
{
}
/// <summary>
/// 实例化一个对象,指定接收或是发送的数据长度
/// </summary>
/// <param name="length">数据长度</param>
public StateObjectAsync( int length ) : base( length )
{
}
#endregion
public System.Threading.Tasks.TaskCompletionSource<T> Tcs { get; set; }
}
#endif
}