From f86cbd83d86473f405ec60a7a78cf28c64150f31 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 13 Jan 2025 15:29:39 +0800 Subject: Refactor mx stuff --- main.go | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 4a4f242..51540f9 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,7 @@ package main import ( - "context" "flag" - "net" "go.lindenii.runxiyu.org/lindenii-common/clog" ) @@ -19,33 +17,8 @@ func main() { clog.Fatal(1, "Error while loading configuration file: "+err.Error()) } - listener, err := net.Listen(config.MX.Net, config.MX.Addr) - if err != nil { - clog.Fatal(1, "MX: Cannot listen: "+err.Error()) - } - defer listener.Close() - clog.Info("MX: Listening via " + config.MX.Net + " on " + config.MX.Addr) + go serve_mx() - for { - conn, err := listener.Accept() - if err != nil { - clog.Error("MX: Cannot accept connection: " + err.Error()) - } - clog.Info("MX: Accepted connection from " + conn.RemoteAddr().String()) - - go func() { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - err := handle_mx_recv_conn(ctx, conn) - if err != nil { - if err == err_connection_handler_eof { - clog.Info("MX: Connection for " + conn.RemoteAddr().String() + " closed with EOF") - } else { - clog.Error("MX: Connection handler for " + conn.RemoteAddr().String() + " returned error: " + err.Error()) - } - } else { - clog.Info("MX: Connection for " + conn.RemoteAddr().String() + " closed gracefully") - } - }() - } + deadlock := make(chan struct{}) + deadlock <- struct{}{} } -- cgit v1.2.3