服务器主动连接客户端,发送数据。那么谁负责关这个虚拟连接?
客户端不知道服务器什么时候把数据发完,那看起来是应该服务器来主动关。
服务器关的话有个问题是 连接关闭的优先级比数据包处理优先级高。
// server
conn = Server.Dial(clientId)
conn.Send(data)
conn.Close()
在客户端侧,数据包是塞队列里面等 Receive 的,但实际去 Receive 的时候 Conn 可能已经被标记 close 了。
workaround 想法
diff --git a/csharp/Fastway/EndPoint.cs b/csharp/Fastway/EndPoint.cs
index a961610..fd9817d 100644
--- a/csharp/Fastway/EndPoint.cs
+++ b/csharp/Fastway/EndPoint.cs
@@ -38,13 +38,13 @@ namespace Fastway
public byte[] Receive ()
{
lock (this) {
+ if (this.waitRecv.Count > 0)
+ return this.waitRecv.Dequeue ();
+
if (this.closed)
return null;
-
- if (this.waitRecv.Count == 0)
- return NoMsg;
-
- return this.waitRecv.Dequeue ();
+
+ return NoMsg;
}
}
服务器主动连接客户端,发送数据。那么谁负责关这个虚拟连接?
客户端不知道服务器什么时候把数据发完,那看起来是应该服务器来主动关。
服务器关的话有个问题是 连接关闭的优先级比数据包处理优先级高。
在客户端侧,数据包是塞队列里面等 Receive 的,但实际去 Receive 的时候 Conn 可能已经被标记 close 了。
workaround 想法