-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
48 lines (40 loc) · 764 Bytes
/
server.go
File metadata and controls
48 lines (40 loc) · 764 Bytes
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
package smtpd
import (
"io"
"log"
"os"
)
type Server struct {
Hostname string
Mailer Mailer
IOLoop IOLoop
commands map[string]commandFactory
}
func NewServer() *Server {
host, err := os.Hostname()
if err != nil {
log.Println("No hostname available. Using 'local'")
host = "local"
}
return &Server{
Hostname: host,
commands: defaultCommands(),
}
}
func (s *Server) Run() {
err := s.IOLoop.Run(s.accept)
if err != nil {
panic(err)
}
}
func (s *Server) accept(r io.ReadCloser, w io.Writer) {
channel := &WriterChannel{w: w, host: s.Hostname}
exchange := NewExchange(s.Mailer, r, channel)
loop := &protocolLoop{
ex: exchange,
commands: s.commands,
next: []string{CommandHelo},
waiting: true,
}
loop.Run()
}