I think you can't. The listen backlog is set to whatever is kernel's maximum backlog value.

See for example /usr/local/go/src/net/sock_linux.go to see how that is determined.

There has been a bug report about it: https://github.com/golang/go/issues/6079

I think it has been incorrectly closed (or alternatively I am missing how to set it).

Workarounds:

 * Create the socket yourself using syscall.Socket, syscall.Bind and
   syscall.Listen and then use net.FileListener.
 * Lower the kernel backlog value. Note that this will affect all
   processes on the system.

Best regards,

Janne Snabb
[email protected]

On 22/03/2019 18.48, Wangbo wrote:
I know Control func and syscall.SetsockoptInt(fd, syscall.AF_INET, syscall.SO_REUSEADDR, 1)  cat set reuseadd
But how to adjust listen backlog since i never find socket options for it.

Agniva De Sarker <[email protected] <mailto:[email protected]>> 于2019年3月22日周五 下午4:44写道:

    Using ListenConfig is the way to go.

    The Control func is passed the raw socket connection on which you
    can apply whatever socket options you choose. You have to go
    through 2 layers to get to the fd.

    ListenConfig{
     Control: func(conn syscall.RawConn) error {
       return conn.Control(func(fd uintptr) error {
         return syscall.SetsockoptInt(fd, syscall.AF_INET, 0, 0)
       })
      }
    }


    On Thursday, 21 March 2019 20:49:20 UTC+5:30, Peter Wang wrote:

        I try to use net.ListenConfig, but fail
        can someone give example ?

-- You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to [email protected]
    <mailto:[email protected]>.
    For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to