-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.go
42 lines (34 loc) · 825 Bytes
/
server.go
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
// mailpopbox
// Copyright 2020 Blue Static <https://www.bluestatic.org>
// This program is free software licensed under the GNU General Public License,
// version 3.0. The full text of the license can be found in LICENSE.txt.
// SPDX-License-Identifier: GPL-3.0-only
package main
import (
"net"
"os"
"os/signal"
"syscall"
"go.uber.org/zap"
)
type ServerControlMessage int
const (
ServerControlFatalError ServerControlMessage = iota
ServerControlRestart
)
func RunAcceptLoop(l net.Listener, c chan<- net.Conn, log *zap.Logger) {
for {
conn, err := l.Accept()
if err != nil {
log.Error("accept", zap.Error(err))
close(c)
return
}
c <- conn
}
}
func CreateReloadSignal() <-chan os.Signal {
reloadChan := make(chan os.Signal, 1)
signal.Notify(reloadChan, syscall.SIGHUP)
return reloadChan
}