From 1e5c0b54f30527acb56d3f364b4dd0ba6ebc0019 Mon Sep 17 00:00:00 2001 From: Patrick Toca Date: Tue, 23 May 2017 13:35:36 +0100 Subject: [PATCH 1/4] corrected Serve() unreachable code in socks5.go --- socks5.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/socks5.go b/socks5.go index a17be68..55f82ae 100644 --- a/socks5.go +++ b/socks5.go @@ -107,14 +107,19 @@ func (s *Server) ListenAndServe(network, addr string) error { // Serve is used to serve connections from a listener func (s *Server) Serve(l net.Listener) error { + errChan := make(chan error) for { conn, err := l.Accept() if err != nil { return err } - go s.ServeConn(conn) + go func(Conn) { + if err := s.ServeConn(conn); err != nil { + errChan <- err + } + }(conn) + return <-errChan } - return nil } // ServeConn is used to serve a single connection. From 7aae60b40f484815f8fa2f8b6b9f18a6d7a400a0 Mon Sep 17 00:00:00 2001 From: Patrick Toca Date: Tue, 23 May 2017 13:53:41 +0100 Subject: [PATCH 2/4] qualified type as 'net.Conn' in Serve() --- socks5.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/socks5.go b/socks5.go index 55f82ae..f472bb4 100644 --- a/socks5.go +++ b/socks5.go @@ -2,12 +2,11 @@ package socks5 import ( "bufio" + "context" "fmt" "log" "net" "os" - - "golang.org/x/net/context" ) const ( @@ -113,7 +112,7 @@ func (s *Server) Serve(l net.Listener) error { if err != nil { return err } - go func(Conn) { + go func(net.Conn) { if err := s.ServeConn(conn); err != nil { errChan <- err } From f7a56ecb95e33843207e0bd26414f0f1cef3cfd7 Mon Sep 17 00:00:00 2001 From: Patrick Toca Date: Tue, 23 May 2017 14:00:26 +0100 Subject: [PATCH 3/4] back to 'golang.org/x/net/context' --- socks5.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/socks5.go b/socks5.go index f472bb4..b5f1fbc 100644 --- a/socks5.go +++ b/socks5.go @@ -2,11 +2,12 @@ package socks5 import ( "bufio" - "context" "fmt" "log" "net" "os" + + "golang.org/x/net/context" ) const ( From b20f9b8ef82d46349602a7f590d9cd4810599aca Mon Sep 17 00:00:00 2001 From: Patrick Toca Date: Tue, 23 May 2017 20:32:57 +0100 Subject: [PATCH 4/4] Serve() return error completed --- socks5.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/socks5.go b/socks5.go index b5f1fbc..a8269d8 100644 --- a/socks5.go +++ b/socks5.go @@ -50,7 +50,7 @@ type Config struct { Dial func(ctx context.Context, network, addr string) (net.Conn, error) } -// Server is reponsible for accepting connections and handling +// Server is responsible for accepting connections and handling // the details of the SOCKS5 protocol type Server struct { config *Config @@ -116,6 +116,8 @@ func (s *Server) Serve(l net.Listener) error { go func(net.Conn) { if err := s.ServeConn(conn); err != nil { errChan <- err + } else { + errChan <- nil } }(conn) return <-errChan