aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/incoming/lmtp
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-08-17 04:48:47 +0800
committerRunxi Yu <me@runxiyu.org>2025-08-17 05:22:09 +0800
commitb6dd3ffce416fa86c223fad5d2f6c3db5d5727e4 (patch)
treef3cc533b1ef5184ee881d9d0103a47ec7f09bd34 /forged/internal/incoming/lmtp
parentAdd shutdown timeouts (diff)
downloadforge-b6dd3ffce416fa86c223fad5d2f6c3db5d5727e4.tar.gz
forge-b6dd3ffce416fa86c223fad5d2f6c3db5d5727e4.tar.zst
forge-b6dd3ffce416fa86c223fad5d2f6c3db5d5727e4.zip
A few other context fixes
Diffstat (limited to 'forged/internal/incoming/lmtp')
-rw-r--r--forged/internal/incoming/lmtp/config.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/forged/internal/incoming/lmtp/config.go b/forged/internal/incoming/lmtp/config.go
index ce32f3d..def3ce9 100644
--- a/forged/internal/incoming/lmtp/config.go
+++ b/forged/internal/incoming/lmtp/config.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net"
+ "time"
"go.lindenii.runxiyu.org/forge/forged/internal/common/misc"
)
@@ -44,25 +45,29 @@ func (server *Server) Run(ctx context.Context) error {
_ = listener.Close()
}()
- go func() {
- <-ctx.Done()
+ stop := context.AfterFunc(ctx, func() {
_ = listener.Close()
- // TODO: Log the error
- }()
+ })
+ defer stop()
for {
conn, err := listener.Accept()
if err != nil {
- if errors.Is(err, net.ErrClosed) {
+ if errors.Is(err, net.ErrClosed) || ctx.Err() != nil {
return nil
}
return fmt.Errorf("accept conn: %w", err)
}
- go server.handleConn(conn)
+ go server.handleConn(ctx, conn)
}
}
-func (server *Server) handleConn(conn net.Conn) {
- panic("TODO: handle LMTP connection")
+func (server *Server) handleConn(ctx context.Context, conn net.Conn) {
+ defer conn.Close()
+ unblock := context.AfterFunc(ctx, func() {
+ _ = conn.SetDeadline(time.Now())
+ _ = conn.Close()
+ })
+ defer unblock()
}