Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions hysteria2/gecko.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func (g *GeckoPacketConn) Upstream() any {
return g.PacketConn
}

func (g *GeckoPacketConn) SetReadBuffer(bytes int) error {
return trySetReadBuffer(g.PacketConn, bytes)
}

func (g *GeckoPacketConn) SetWriteBuffer(bytes int) error {
return trySetWriteBuffer(g.PacketConn, bytes)
}

func (g *GeckoPacketConn) WriteTo(p []byte, addr net.Addr) (int, error) {
if len(p) == 0 {
return 0, nil
Expand Down
29 changes: 29 additions & 0 deletions hysteria2/salamander.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hysteria2

import (
"net"
"os"

"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf"
Expand Down Expand Up @@ -73,6 +74,34 @@ func (s *SalamanderPacketConn) Upstream() any {
return s.PacketConn
}

func (s *SalamanderPacketConn) SetReadBuffer(bytes int) error {
return trySetReadBuffer(s.PacketConn, bytes)
}

func (s *SalamanderPacketConn) SetWriteBuffer(bytes int) error {
return trySetWriteBuffer(s.PacketConn, bytes)
}

func trySetReadBuffer(conn net.PacketConn, bytes int) error {
udpConn, isUDPConn := common.Cast[interface {
SetReadBuffer(bytes int) error
}](conn)
if !isUDPConn {
return os.ErrInvalid
}
return udpConn.SetReadBuffer(bytes)
}

func trySetWriteBuffer(conn net.PacketConn, bytes int) error {
udpConn, isUDPConn := common.Cast[interface {
SetWriteBuffer(bytes int) error
}](conn)
if !isUDPConn {
return os.ErrInvalid
}
return udpConn.SetWriteBuffer(bytes)
}

type VectorisedSalamanderPacketConn struct {
SalamanderPacketConn
writer N.VectorisedPacketWriter
Expand Down