From d158e6df3faefbfef436617a637b4cb69e672951 Mon Sep 17 00:00:00 2001 From: xtaci Date: Thu, 11 Aug 2016 13:20:03 +0800 Subject: [PATCH] set stream max windows size to sockbuff --- client/main.go | 2 +- server/main.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/client/main.go b/client/main.go index be3a686..1035ef1 100644 --- a/client/main.go +++ b/client/main.go @@ -274,7 +274,7 @@ func main() { EnableKeepAlive: true, KeepAliveInterval: 30 * time.Second, ConnectionWriteTimeout: 30 * time.Second, - MaxStreamWindowSize: 16777216, + MaxStreamWindowSize: uint32(sockbuf), LogOutput: os.Stderr, } var session *yamux.Session diff --git a/server/main.go b/server/main.go index 690dfb1..579e44f 100644 --- a/server/main.go +++ b/server/main.go @@ -53,17 +53,10 @@ func newCompStream(conn net.Conn) *compStream { } // handle multiplex-ed connection -func handleMux(conn io.ReadWriteCloser, target string) { +func handleMux(conn io.ReadWriteCloser, target string, config *yamux.Config) { // stream multiplex var mux *yamux.Session - config := &yamux.Config{ - AcceptBacklog: 256, - EnableKeepAlive: true, - KeepAliveInterval: 30 * time.Second, - ConnectionWriteTimeout: 30 * time.Second, - MaxStreamWindowSize: 16777216, - LogOutput: os.Stderr, - } + m, err := yamux.Server(conn, config) if err != nil { log.Println(err) @@ -276,7 +269,14 @@ func main() { if err := lis.SetWriteBuffer(sockbuf); err != nil { log.Println("SetWriteBuffer:", err) } - + config := &yamux.Config{ + AcceptBacklog: 256, + EnableKeepAlive: true, + KeepAliveInterval: 30 * time.Second, + ConnectionWriteTimeout: 30 * time.Second, + MaxStreamWindowSize: uint32(sockbuf), + LogOutput: os.Stderr, + } for { if conn, err := lis.Accept(); err == nil { log.Println("remote address:", conn.RemoteAddr()) @@ -288,9 +288,9 @@ func main() { conn.SetKeepAlive(keepalive) if nocomp { - go handleMux(conn, target) + go handleMux(conn, target, config) } else { - go handleMux(newCompStream(conn), target) + go handleMux(newCompStream(conn), target, config) } } else { log.Println(err)