Skip to content

Commit e069306

Browse files
committed
feat: allow DisableTCPNoDelay to work on TLS connections
1 parent 104a76c commit e069306

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pipe.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package rueidis
33
import (
44
"bufio"
55
"context"
6+
"crypto/tls"
67
"errors"
78
"fmt"
89
"io"
@@ -321,10 +322,19 @@ func (p *pipe) _exit(err error) {
321322
p.clhks.Load().(func(error))(err)
322323
}
323324

325+
func disableNoDelay(conn net.Conn) {
326+
if c, ok := conn.(*tls.Conn); ok {
327+
conn = c.NetConn()
328+
}
329+
if c, ok := conn.(*net.TCPConn); ok {
330+
c.SetNoDelay(false)
331+
}
332+
}
333+
324334
func (p *pipe) _background() {
325335
p.conn.SetDeadline(time.Time{})
326-
if conn, ok := p.conn.(*net.TCPConn); ok && p.noNoDelay {
327-
conn.SetNoDelay(false)
336+
if p.noNoDelay {
337+
disableNoDelay(p.conn)
328338
}
329339
go func() {
330340
p._exit(p._backgroundWrite())

rueidis_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,9 @@ func TestTLSClient(t *testing.T) {
302302

303303
_, port, _ := net.SplitHostPort(ln.Addr().String())
304304
client, err := NewClient(ClientOption{
305-
InitAddress: []string{"127.0.0.1:" + port},
306-
TLSConfig: config,
305+
InitAddress: []string{"127.0.0.1:" + port},
306+
TLSConfig: config,
307+
DisableTCPNoDelay: true,
307308
})
308309
if err != nil {
309310
t.Fatal(err)

0 commit comments

Comments
 (0)