gnet icon indicating copy to clipboard operation
gnet copied to clipboard

[Question]: SetContext has no effect in UDP. Is it intentionally designed this way?

Open ckcfcc opened this issue 5 months ago • 4 comments

Actions I've taken before I'm here

  • [X] I've thoroughly read the documentations about this problem but still have no answer.
  • [X] I've searched the Github Issues/Discussions but didn't find any similar problems that have been solved.
  • [X] I've searched the internet for this problem but didn't find anything helpful.

Questions with details

在UDP中,只有OnTraffic会生效,所以我用OnTraffic的参数conn来标识一个UDP客户端,但是使用中发现即使是不同的物理机发起数据表,每次再次进入OnTraffic的conn.Context() 得到的结果都是nil。

我进一步学习了OnTraffic的源代码调用,发现每次的conn在触发OnTraffic都会被释放。感觉是故意为之。

请问是否能否有办法,让一个同源的udp客户端连接后固定分配一个conn对象而不释放,这样context才有更多的用处,否则,使用时还要自己再设计一个封装来更具remoteAddr来确定一个连接信息来绑定 context,感觉有点多此一举。 希望gnet中就能提供这样的功能,对于同源(同一个remoteAddr)来说使用同一个conn。

可以提供一个超时机制设置,比如多时间后,这个客户端没有发送和收任何数据包,就标记为已经废弃或者回收掉。

不知是否可行?

这个issue好像和 UDP with unique fds for each "connection"有点类似,但是那个issue好像是主要强调唯一性,这个主要是想在udp的conn上使用conn.Context()

Code snippets (optional)

No response

ckcfcc avatar Sep 15 '24 07:09 ckcfcc