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

Special treatment for the first package #601

Closed
skyw4code opened this issue May 13, 2024 · 8 comments
Closed

Special treatment for the first package #601

skyw4code opened this issue May 13, 2024 · 8 comments
Labels
help wanted Extra attention is needed question Further information is requested wontfix This will not be worked on

Comments

@skyw4code
Copy link

skyw4code commented May 13, 2024

遇到了不少场景(如:支持PROXY Protocol协议),都需要在连接建立后对首个包进行特殊处理,当然放在协议解析器里面去处理是可以的,但很明显这样每次数据包来的时候都得去判断一下,很不合理,解析器应该只关心业务相关内容才对!!!

翻了一下Issues,发现之前已经有提过这个了,
#231 (comment)
#231 (comment)
pan大佬也说了解决的思路:应该有一个专门的 handler,收到第一个包的时候调用一下就行。。。
这么久过去了,有计划支持吗?

@skyw4code skyw4code added help wanted Extra attention is needed question Further information is requested labels May 13, 2024
@gh-translator gh-translator changed the title 首个包特殊处理 Special treatment for the first package May 13, 2024
@panjf2000
Copy link
Owner

这个问题主要是 gnet v1 里出现的,因为 v1 有编码器和解码器的功能,导致解码器在识别第一个特殊包的场景中不是很灵活,但是 gnet v2 移除了编码器和解码器,现在整个数据解析逻辑都要放在 OnTraffic() 里了,更加灵活,就没必要再设置一个所谓的 handler 了,用户自己判断一下第一个包然后处理就行了。

@gh-translator
Copy link
Collaborator

🤖 Non-English text detected, translating...


This problem mainly occurs in gnet v1, because v1 has the functions of encoder and decoder, resulting in the decoder not being very flexible in the scenario of identifying the first special packet, but gnet v2 removes the encoder and decoder. Now the entire data parsing logic will be placed in OnTraffic(), which is more flexible. There is no need to set up a so-called handler. The user can just judge the first package and process it.

@skyw4code
Copy link
Author

skyw4code commented May 14, 2024

这个问题主要是 gnet v1 里出现的,因为 v1 有编码器和解码器的功能,导致解码器在识别第一个特殊包的场景中不是很灵活,但是 gnet v2 移除了编码器和解码器,现在整个数据解析逻辑都要放在 OnTraffic() 里了,更加灵活,就没必要再设置一个所谓的 handler 了,用户自己判断一下第一个包然后处理就行了。

是~~~
其实纠结的是后面每次数据包来的时候也得都去判断一下,这个很难受...

@gh-translator
Copy link
Collaborator

🤖 Non-English text detected, translating...


This problem mainly occurs in gnet v1, because v1 has the functions of encoder and decoder, resulting in the decoder not being very flexible in the scenario of identifying the first special packet, but gnet v2 removes the encoder and decoder , now the entire data parsing logic must be placed in OnTraffic(), which is more flexible. There is no need to set up a so-called handler. The user can just judge the first package and then process it.

Yes~~~
In fact, the struggle is that every time a data packet comes, it has to be judged. This is very uncomfortable...

@panjf2000
Copy link
Owner

不需要每次都判断,你用 sync.Once 或者更简单地在 c.Context 里设置一个 bool,第一个包解析完之后就设个标志,下次判断一下这个标志,跳过就行了。

@gh-translator
Copy link
Collaborator

🤖 Non-English text detected, translating...


You don’t need to judge every time. You can use sync.Once or simply set a bool in c.Context. After the first package is parsed, set a flag. Next time, judge this flag and skip it. That's it.

@panjf2000 panjf2000 added the wontfix This will not be worked on label May 14, 2024
@skyw4code
Copy link
Author

skyw4code commented May 14, 2024

下次判断一下这个标志,跳过就行了。

emmm... 我说的就是这个判断,这也是判断啊...

@gh-translator
Copy link
Collaborator

🤖 Non-English text detected, translating...


Judge this sign next time and just skip it.

    • ! This is the judgment I am talking about. This is also a judgment...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants