func (svr *server) accept(fd int, _ netpoll.IOEvent) error {
nfd, sa, err := unix.Accept(fd)
if err != nil {
if err == unix.EAGAIN || err == unix.ECONNABORTED {
return nil
}
svr.opts.Logger.Errorf("Accept() fails due to error: %v", err)
return errors.ErrAcceptSocket
}
if err = os.NewSyscallError("fcntl nonblock", unix.SetNonblock(nfd, true)); err != nil {
return err
}
remoteAddr := socket.SockaddrToTCPOrUnixAddr(sa)
if svr.opts.TCPKeepAlive > 0 && svr.ln.network == "tcp" {
err = socket.SetKeepAlive(nfd, int(svr.opts.TCPKeepAlive/time.Second))
logging.Error(err)
}
el := svr.lb.next(remoteAddr)
c := newTCPConn(nfd, el, sa, svr.opts.Codec, el.ln.addr, remoteAddr)
err = el.poller.UrgentTrigger(el.register, c)
if err != nil {
_ = unix.Close(nfd)
c.releaseTCP()
}
return nil
}
Major version of gnet
v1
Specific version of gnet
v1.6.7
Operating system
Linux
Relevant log output
无
Code snippets (optional)
建议是否可以修改为这样,我认为用户的配置应该对于accept到的socket也要生效
func (svr *server) accept(fd int, _ netpoll.IOEvent) error {
nfd, sa, err := unix.Accept(fd)
if err != nil {
if err == unix.EAGAIN || err == unix.ECONNABORTED {
return nil
}
svr.opts.Logger.Errorf("Accept() fails due to error: %v", err)
return errors.ErrAcceptSocket
}
if err = os.NewSyscallError("fcntl nonblock", unix.SetNonblock(nfd, true)); err != nil {
return err
}
remoteAddr := socket.SockaddrToTCPOrUnixAddr(sa)
if svr.opts.TCPKeepAlive > 0 && svr.ln.network == "tcp" {
err = socket.SetKeepAlive(nfd, int(svr.opts.TCPKeepAlive/time.Second))
logging.Error(err)
}
// Set RecvBufferSize
if svr.opts.SocketRecvBuffer > 0 {
err = socket.SetRecvBuffer(nfd, svr.opts.SocketRecvBuffer)
logging.Error(err)
}
// SetSendBufferSize
if svr.opts.SocketSendBuffer > 0 {
err = socket.SetSendBuffer(nfd, svr.opts.SocketRecvBuffer)
logging.Error(err)
}
// Disabling TIME_WAIT state
l := unix.Linger{
Onoff: 0,
Linger: 0,
}
err = unix.SetsockoptLinger(nfd, unix.SOL_SOCKET, unix.SO_LINGER, &l)
if err != nil {
logging.Error(err)
}
el := svr.lb.next(remoteAddr)
c := newTCPConn(nfd, el, sa, svr.opts.Codec, el.ln.addr, remoteAddr)
err = el.poller.UrgentTrigger(el.register, c)
if err != nil {
_ = unix.Close(nfd)
c.releaseTCP()
}
return nil
}
### How to Reproduce
Steps to reproduce the behavior:
1. Go to '....'
2. Click on '....'
3. Do '....'
4. See '....'
### Does this issue reproduce with the latest release?
It can reproduce with the latest release
Actions I've taken before I'm here
What happened?
在linux系上,用户初始化gnet时,如果配置了socket相关配置,如:接受缓冲区长度,nodely, 关闭timewait等设置 在accept之后,是否应该对于新的文件描述服也要应用对应设置? 代码如下:
accept 代码
Major version of gnet
v1
Specific version of gnet
v1.6.7
Operating system
Linux
Relevant log output
Code snippets (optional)