aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/lmtp/config.go
blob: ce22740e38aca4e4e25c9517258b183ce63fe890 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

package lmtp

import (
	"fmt"
	"net"

	"go.lindenii.runxiyu.org/forge/forged/internal/misc"
)

type Pool struct {
	socket       string
	domain       string
	maxSize      int64
	writeTimeout uint32
	readTimeout  uint32
}

type Config struct {
	Socket       string `scfg:"socket"`
	Domain       string `scfg:"domain"`
	MaxSize      int64  `scfg:"max_size"`
	WriteTimeout uint32 `scfg:"write_timeout"`
	ReadTimeout  uint32 `scfg:"read_timeout"`
}

func New(config Config) (pool Pool) {
	pool.socket = config.Socket
	pool.domain = config.Domain
	pool.maxSize = config.MaxSize
	pool.writeTimeout = config.WriteTimeout
	pool.readTimeout = config.ReadTimeout
	return pool
}

func (pool *Pool) Run() error {
	listener, _, err := misc.ListenUnixSocket(pool.socket)
	if err != nil {
		return fmt.Errorf("listen unix socket for LMTP: %w", err)
	}

	for {
		conn, err := listener.Accept()
		if err != nil {
			return fmt.Errorf("accept conn: %w", err)
		}

		go pool.handleConn(conn)
	}
}

func (pool *Pool) handleConn(conn net.Conn) {
	panic("TODO: handle LMTP connection")
}