Skip to content

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

Description

@patricksuo

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

// 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;
                        }
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions