From 2f8d47fe368c59da72c5c5a1cfb86d6895f03ebf Mon Sep 17 00:00:00 2001 From: rachel-mp4 Date: Thu, 31 Jul 2025 18:45:14 -0400 Subject: [PATCH] add denagle --- server.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server.go b/server.go index 0e6f701..aca79f8 100644 --- a/server.go +++ b/server.go @@ -7,6 +7,7 @@ import ( "github.com/rachel-mp4/lrcproto/gen/go" "google.golang.org/protobuf/proto" "log" + "net" "net/http" "sync" "time" @@ -174,6 +175,14 @@ func (s *Server) WSHandler() http.HandlerFunc { } defer conn.Close() + if netConn := conn.UnderlyingConn(); netConn != nil { + if tcpConn, ok := netConn.(*net.TCPConn); ok { + if err := tcpConn.SetNoDelay(true); err != nil { + log.Println("failed to denagle") + } + } + } + ctx, cancel := context.WithCancel(context.Background()) client := &client{ conn: conn, -- 2.51.2