milter-experiment/socket.go

28 lines
707 B
Go
Raw Normal View History

package main
import (
"bufio"
2019-05-12 21:08:27 +02:00
"fmt"
"net"
)
2019-05-12 21:08:27 +02:00
func runServer() error {
serverSocket, err := net.Listen("tcp", "127.0.0.1:7777")
if err != nil {
2019-05-12 21:08:27 +02:00
myError := fmt.Errorf("could not create listening socket: %s", err.Error())
return myError
}
2019-05-12 21:08:27 +02:00
logger.Infof("Now listening for incoming connections.\n")
defer serverSocket.Close()
for {
clientConnection, err := serverSocket.Accept()
if err != nil {
logger.Warnf("Could not accept client connection: %s\n", err.Error())
} else {
logger.Infof("Accepted client connection.\n")
milterReadWriter := bufio.NewReadWriter(bufio.NewReader(clientConnection), bufio.NewWriter(clientConnection))
go handleMtaConnection(milterReadWriter)
}
}
}