return err on Serve instead of log.Print

master
fangdingjun 6 years ago
parent 0477b2d842
commit fc6f0a9ee1

@ -4,7 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io" "io"
"log" //"log"
"net" "net"
) )
@ -37,13 +37,14 @@ type socks4Conn struct {
dial DialFunc dial DialFunc
} }
func (s4 *socks4Conn) Serve(b []byte, n int) { func (s4 *socks4Conn) Serve(b []byte, n int) (err error) {
defer s4.Close() defer s4.Close()
if err := s4.processRequest(b, n); err != nil { if err = s4.processRequest(b, n); err != nil {
log.Println(err) //log.Println(err)
return return
} }
return
} }
func (s4 *socks4Conn) Close() { func (s4 *socks4Conn) Close() {

@ -4,7 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log" //"log"
"net" "net"
//"strconv" //"strconv"
"encoding/binary" "encoding/binary"
@ -56,18 +56,19 @@ type socks5Conn struct {
auth AuthService auth AuthService
} }
func (s5 *socks5Conn) Serve(b []byte, n int) { func (s5 *socks5Conn) Serve(b []byte, n int) (err error) {
defer s5.Close() defer s5.Close()
if err := s5.handshake(b, n); err != nil { if err = s5.handshake(b, n); err != nil {
log.Println(err) //log.Println(err)
return return
} }
if err := s5.processRequest(); err != nil { if err = s5.processRequest(); err != nil {
log.Println(err) //log.Println(err)
return return
} }
return
} }
func (s5 *socks5Conn) handshake(buf []byte, n int) (err error) { func (s5 *socks5Conn) handshake(buf []byte, n int) (err error) {

Loading…
Cancel
Save