aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-01-13 15:11:07 +0800
committerRunxi Yu <me@runxiyu.org>2025-01-13 15:11:07 +0800
commit1c2ca837538468b080e20acf2460959ed98c0e07 (patch)
tree45ccf03c062dc8bfb8bb95e3ce9af5331cf353e1
parentUpdate logging code (diff)
downloadmaild-1c2ca837538468b080e20acf2460959ed98c0e07.tar.gz
maild-1c2ca837538468b080e20acf2460959ed98c0e07.tar.zst
maild-1c2ca837538468b080e20acf2460959ed98c0e07.zip
Log EOF differently from other errors
Diffstat (limited to '')
-rw-r--r--errors.go5
-rw-r--r--main.go14
-rw-r--r--mx_recv.go4
3 files changed, 16 insertions, 7 deletions
diff --git a/errors.go b/errors.go
index 7ee429a..b0d0247 100644
--- a/errors.go
+++ b/errors.go
@@ -5,7 +5,10 @@ import (
"strings"
)
-var err_unsupported_database_type = errors.New("Unsupported database type; only \"postgres\" is currently supported")
+var (
+ err_unsupported_database_type = errors.New("Unsupported database type; only \"postgres\" is currently supported")
+ err_connection_handler_eof = errors.New("Connection handler encountered EOF")
+)
type err_local_recipients_not_found_t []string
diff --git a/main.go b/main.go
index bf503f4..c3a2e16 100644
--- a/main.go
+++ b/main.go
@@ -2,9 +2,7 @@ package main
import (
"context"
- "errors"
"flag"
- "io"
"net"
"go.lindenii.runxiyu.org/lindenii-common/clog"
@@ -31,7 +29,7 @@ func main() {
for {
conn, err := listener.Accept()
if err != nil {
- clog.Error("MX: Cannot accept connection: "+err.Error())
+ clog.Error("MX: Cannot accept connection: " + err.Error())
}
clog.Info("MX: Accepted connection from " + conn.RemoteAddr().String())
@@ -39,10 +37,14 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := handle_mx_recv_conn(ctx, conn)
- if err != nil && !errors.Is(err, io.EOF) {
- clog.Error("MX: Connection handler for " + conn.RemoteAddr().String() + " returned error: " + err.Error())
+ 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.Error("MX: Connection handler for " + conn.RemoteAddr().String() + " returned error: " + err.Error())
+ clog.Info("MX: Connection for " + conn.RemoteAddr().String() + " closed gracefully")
}
}()
}
diff --git a/mx_recv.go b/mx_recv.go
index ef8c2cc..33b4012 100644
--- a/mx_recv.go
+++ b/mx_recv.go
@@ -6,6 +6,7 @@ import (
"context"
"crypto/tls"
"errors"
+ "io"
"net"
"slices"
"strings"
@@ -49,6 +50,9 @@ func (session *mx_recv_session) handle(ctx context.Context) error {
for {
line, err := session.buf_conn.ReadString('\n')
if err != nil {
+ if err == io.EOF {
+ return err_connection_handler_eof
+ }
return err
}
line = strings.TrimSuffix(line, "\n")