gnet icon indicating copy to clipboard operation
gnet copied to clipboard

[Feature]: 可否暴露出setTos方法支持设置IP头的ToS字段

Open liuyingiscookie opened this issue 2 years ago • 4 comments

Description of new feature

可否暴露出setTos方法支持设置IP头的ToS字段

Scenarios for new feature

目前我们的项目使用gnet。在最新版本的更新中,需要设置TOS字段。但是目前gnet没有暴露出对应的方法,可否支持一下

Breaking changes or not?

No

Code snippets (optional)

No response

Alternatives for new feature

None.

Additional context (optional)

None.

liuyingiscookie avatar Feb 21 '23 09:02 liuyingiscookie

直接通过 syscall 设置不行吗?

panjf2000 avatar Feb 21 '23 11:02 panjf2000

通过系统调用 setsockopt 设置 tos 即可,可以参考:https://cs.opensource.google/go/x/net/+/master:ipv4/genericopt.go;l=21;drc=c63010009c802314a29324ce49987897f9838e29?q=settos&ss=go%2Fx%2Fnet

panjf2000 avatar Feb 21 '23 11:02 panjf2000

抱歉,我没有描述清楚,我们使用的gnet.server。最终会通过接口 React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action)中提供的入参c去进行c.SendTo()重新回包,这里的conn我的理解是该框架封装的,并没有办法可以去获得Controller并回调setsockopt设置tos

liuyingiscookie avatar Feb 21 '23 12:02 liuyingiscookie

你们用的是 1.x 版本吧,conn 应该没有 Fd() 返回 fd,我理解是不是新增一个 API 返回 fd 给你,你自己去设置就行了?

panjf2000 avatar Mar 02 '23 11:03 panjf2000