aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go33
-rw-r--r--serve_mx.go (renamed from mx_recv.go)33
2 files changed, 36 insertions, 30 deletions
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{}{}
}
diff --git a/mx_recv.go b/serve_mx.go
index 33b4012..f3c1527 100644
--- a/mx_recv.go
+++ b/serve_mx.go
@@ -13,6 +13,7 @@ import (
"github.com/jackc/pgx/v5/pgxpool"
"go.lindenii.runxiyu.org/lindenii-common/mailkit"
+ "go.lindenii.runxiyu.org/lindenii-common/clog"
)
type server_state_t uint
@@ -229,3 +230,35 @@ func handle_mx_recv_conn(ctx context.Context, net_conn net.Conn) error {
}
return session.handle(ctx)
}
+
+func serve_mx() {
+ 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)
+
+ 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")
+ }
+ }()
+ }
+}