Skip to content

Commit 17736a5

Browse files
committed
修复当发送数据检查出错后, 因为某些原因包混乱了, 导致后面发送数据依然出错的问题
主要原因是在类初始化时使用了public MemoryStream stream = MemoryStream.createObject();, 导致后面新new的bundle实际也是引用了这个stream, 而这个stream之前被写入了错误的数据。 #10
1 parent 432ee0b commit 17736a5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Bundle.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
public class Bundle : ObjectPool<Bundle>
1414
{
15-
public MemoryStream stream = MemoryStream.createObject();
15+
public MemoryStream stream = new MemoryStream();
1616
public List<MemoryStream> streamList = new List<MemoryStream>();
1717
public int numMessage = 0;
1818
public int messageLength = 0;
@@ -22,6 +22,25 @@ public class Bundle : ObjectPool<Bundle>
2222
public Bundle()
2323
{
2424
}
25+
26+
public void clear()
27+
{
28+
stream = MemoryStream.createObject();
29+
streamList = new List<MemoryStream>();
30+
numMessage = 0;
31+
messageLength = 0;
32+
msgtype = null;
33+
_curMsgStreamIndex = 0;
34+
}
35+
36+
/// <summary>
37+
/// 把自己放回缓冲池
38+
/// </summary>
39+
public void reclaimObject()
40+
{
41+
clear();
42+
reclaimObject(this);
43+
}
2544

2645
public void newMessage(Message mt)
2746
{

0 commit comments

Comments
 (0)