Commit 3ea57088 authored by Yang.Liu's avatar Yang.Liu Committed by ginuerzh

Fix: relay udp forward

parent 1c32df37
...@@ -257,10 +257,11 @@ func (h *relayHandler) Handle(conn net.Conn) { ...@@ -257,10 +257,11 @@ func (h *relayHandler) Handle(conn net.Conn) {
type relayConn struct { type relayConn struct {
net.Conn net.Conn
isServer bool isServer bool
udp bool udp bool
wbuf bytes.Buffer wbuf bytes.Buffer
once sync.Once once sync.Once
headerSent bool
} }
func (c *relayConn) Read(b []byte) (n int, err error) { func (c *relayConn) Read(b []byte) (n int, err error) {
...@@ -323,6 +324,7 @@ func (c *relayConn) Write(b []byte) (n int, err error) { ...@@ -323,6 +324,7 @@ func (c *relayConn) Write(b []byte) (n int, err error) {
var bb [2]byte var bb [2]byte
binary.BigEndian.PutUint16(bb[:2], uint16(len(b))) binary.BigEndian.PutUint16(bb[:2], uint16(len(b)))
c.wbuf.Write(bb[:]) c.wbuf.Write(bb[:])
c.headerSent = true
} }
c.wbuf.Write(b) // append the data to the cached header c.wbuf.Write(b) // append the data to the cached header
// _, err = c.Conn.Write(c.wbuf.Bytes()) // _, err = c.Conn.Write(c.wbuf.Bytes())
...@@ -334,7 +336,13 @@ func (c *relayConn) Write(b []byte) (n int, err error) { ...@@ -334,7 +336,13 @@ func (c *relayConn) Write(b []byte) (n int, err error) {
if !c.udp { if !c.udp {
return c.Conn.Write(b) return c.Conn.Write(b)
} }
if !c.headerSent {
c.headerSent = true
b2 := make([]byte, len(b)+2)
copy(b2, b)
_, err = c.Conn.Write(b2)
return
}
nsize := 2 + len(b) nsize := 2 + len(b)
var buf []byte var buf []byte
if nsize <= mediumBufferSize { if nsize <= mediumBufferSize {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment