Bläddra i källkod

tcp AcceptTCP

ls 5 år sedan
förälder
incheckning
484ef42ff7
2 ändrade filer med 15 tillägg och 13 borttagningar
  1. 4 4
      logger.go
  2. 11 9
      tcp/server.go

+ 4 - 4
logger.go

@@ -57,13 +57,13 @@ func CloseDefaultLogger() error {
 // LogInfo log info
 func LogInfo(v ...interface{}) {
 	deflog.Log.SetPrefix("[INFO]")
-	deflog.Log.Println(v)
+	deflog.Log.Println(v...)
 }
 
 // LogDebug log debug
 func LogDebug(v ...interface{}) {
 	deflog.Log.SetPrefix("[DEBUG]")
-	deflog.Log.Println(v)
+	deflog.Log.Println(v...)
 }
 
 // NewLogger new
@@ -87,11 +87,11 @@ func (logger Logger) Close() error {
 // Info log info
 func (logger Logger) Info(v ...interface{}) {
 	logger.Log.SetPrefix("[INFO]")
-	logger.Log.Println(v)
+	logger.Log.Println(v...)
 }
 
 // Debug log debug
 func (logger Logger) Debug(v ...interface{}) {
 	logger.Log.SetPrefix("[DEBUG]")
-	logger.Log.Println(v)
+	logger.Log.Println(v...)
 }

+ 11 - 9
tcp/server.go

@@ -41,20 +41,22 @@ func NewTCPServer(addr string, cb func(*net.TCPConn)) {
 		//log..Log("Protocol", "HTTP", "addr", addr)
 		//errc <- server.ListenAndServe()
 		for {
-			conn, err := listen.Accept()
+			conn, err := listen.AcceptTCP()
 			if err != nil {
 				errc <- err
 				log.Fatalf("accept error: %v", err)
 				break
 			}
-
-			tcpConn, ok := conn.(*net.TCPConn)
-			if !ok {
-				//error handle
-				conn.Close()
-				continue
-			}
-			go cb(tcpConn)
+			go cb(conn)
+			/*
+				tcpConn, ok := conn.(*net.TCPConn)
+				if !ok {
+					//error handle
+					conn.Close()
+					continue
+				}
+				go cb(tcpConn)
+				// */
 		}
 		logger.Println("Exit server", "Quit")
 	}()