From d1d71e9e38c0d3f08e166964fc092d3607145387 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Tue, 15 Sep 2015 21:40:51 +0200 Subject: [PATCH] use buffered io for socks input --- net/socks/socks.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/socks/socks.go b/net/socks/socks.go index 92c9720ce..3538cfb4d 100644 --- a/net/socks/socks.go +++ b/net/socks/socks.go @@ -1,6 +1,7 @@ package socks import ( + "bufio" "errors" "net" "strconv" @@ -60,8 +61,10 @@ func (server *SocksServer) AcceptConnections(listener net.Listener) error { func (server *SocksServer) HandleConnection(connection net.Conn) error { defer connection.Close() + + reader := bufio.NewReader(connection) - auth, err := socksio.ReadAuthentication(connection) + auth, err := socksio.ReadAuthentication(reader) if err != nil { log.Error("Error on reading authentication: %v", err) return err @@ -83,7 +86,7 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { authResponse := socksio.NewAuthenticationResponse(socksio.AuthNotRequired) socksio.WriteAuthentication(connection, authResponse) - request, err := socksio.ReadRequest(connection) + request, err := socksio.ReadRequest(reader) if err != nil { log.Error("Error on reading socks request: %v", err) return err @@ -118,7 +121,7 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { readFinish := make(chan bool) writeFinish := make(chan bool) - go server.dumpInput(connection, input, readFinish) + go server.dumpInput(reader, input, readFinish) go server.dumpOutput(connection, output, writeFinish) <-writeFinish