Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

服务端主动连接客户端情景下的网络事件优先级问题 #6

Open
patricksuo opened this issue Mar 27, 2017 · 0 comments
Open

Comments

@patricksuo
Copy link
Contributor

服务器主动连接客户端,发送数据。那么谁负责关这个虚拟连接?
客户端不知道服务器什么时候把数据发完,那看起来是应该服务器来主动关。
服务器关的话有个问题是 连接关闭的优先级比数据包处理优先级高。

// 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;
                        }
                }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant