diff --git a/client_test.go b/client_test.go index d1c89f458..1f446501c 100644 --- a/client_test.go +++ b/client_test.go @@ -439,6 +439,7 @@ func runClient(t *testing.T, network, addr string, et, reuseport, multicore, asy clientEV := &clientEvents{tester: t, packetLen: streamLen, svr: ts} ts.client, err = NewClient( clientEV, + WithTCPNoDelay(TCPNoDelay), WithLockOSThread(true), WithTicker(true), ) @@ -456,7 +457,6 @@ func runClient(t *testing.T, network, addr string, et, reuseport, multicore, asy WithReusePort(reuseport), WithTicker(true), WithTCPKeepAlive(time.Minute*1), - WithTCPNoDelay(TCPDelay), WithLoadBalancing(lb)) assert.NoError(t, err) } @@ -657,7 +657,6 @@ func TestClientReadOnEOF(t *testing.T) { cli, err := NewClient(ev, WithSocketRecvBuffer(4*1024), WithSocketSendBuffer(4*1024), - WithTCPNoDelay(TCPDelay), WithTCPKeepAlive(time.Minute), WithLogger(zap.NewExample().Sugar()), WithReadBufferCap(32*1024), diff --git a/client_unix.go b/client_unix.go index 0ce24f463..2d82f8e98 100644 --- a/client_unix.go +++ b/client_unix.go @@ -208,8 +208,8 @@ func (cli *Client) EnrollContext(c net.Conn, ctx interface{}) (Conn, error) { ua.Name = c.RemoteAddr().String() + "." + strconv.Itoa(dupFD) gc = newTCPConn(dupFD, cli.el, sockAddr, c.LocalAddr(), c.RemoteAddr()) case *net.TCPConn: - if cli.opts.TCPNoDelay == TCPDelay { - if err = socket.SetNoDelay(dupFD, 0); err != nil { + if cli.opts.TCPNoDelay == TCPNoDelay { + if err = socket.SetNoDelay(dupFD, 1); err != nil { return nil, err } } diff --git a/gnet_test.go b/gnet_test.go index 7c341d45b..3147bb70f 100644 --- a/gnet_test.go +++ b/gnet_test.go @@ -643,7 +643,7 @@ func runServer(t *testing.T, addrs []string, et, reuseport, multicore, async, wr WithReusePort(reuseport), WithTicker(true), WithTCPKeepAlive(time.Minute), - WithTCPNoDelay(TCPDelay), + WithTCPNoDelay(TCPNoDelay), WithLoadBalancing(lb)) } else { err = Run(ts, diff --git a/options.go b/options.go index 86caef7fb..ef50639d1 100644 --- a/options.go +++ b/options.go @@ -98,9 +98,12 @@ type Options struct { // TCPNoDelay controls whether the operating system should delay // packet transmission in hopes of sending fewer packets (Nagle's algorithm). + // When this option is assign to TCPNoDelay, TCP_NODELAY socket option will + // be turned on, on the contrary, if it is assigned to TCPDelay, the socket + // option will be turned off. // - // The default is true (no delay), meaning that data is sent - // as soon as possible after a write operation. + // The default is TCPNoDelay, meaning that TCP_NODELAY is turned on and data + // will not be buffered but sent as soon as possible after a write operation. TCPNoDelay TCPSocketOpt // SocketRecvBuffer sets the maximum socket receive buffer in bytes.