Skip to content

Commit

Permalink
feat: allow DisableTCPNoDelay to work on TLS connections
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <rueiancsie@gmail.com>
  • Loading branch information
rueian committed Nov 26, 2024
1 parent 8d426f7 commit 02a3460
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 12 additions & 2 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package valkey
import (
"bufio"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -321,10 +322,19 @@ func (p *pipe) _exit(err error) {
p.clhks.Load().(func(error))(err)
}

func disableNoDelay(conn net.Conn) {
if c, ok := conn.(*tls.Conn); ok {
conn = c.NetConn()
}
if c, ok := conn.(*net.TCPConn); ok {
c.SetNoDelay(false)
}
}

func (p *pipe) _background() {
p.conn.SetDeadline(time.Time{})
if conn, ok := p.conn.(*net.TCPConn); ok && p.noNoDelay {
conn.SetNoDelay(false)
if p.noNoDelay {
disableNoDelay(p.conn)
}
go func() {
p._exit(p._backgroundWrite())
Expand Down
5 changes: 3 additions & 2 deletions valkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@ func TestTLSClient(t *testing.T) {

_, port, _ := net.SplitHostPort(ln.Addr().String())
client, err := NewClient(ClientOption{
InitAddress: []string{"127.0.0.1:" + port},
TLSConfig: config,
InitAddress: []string{"127.0.0.1:" + port},
TLSConfig: config,
DisableTCPNoDelay: true,
})
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 02a3460

Please sign in to comment.