2019-05-12 19:05:56 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2019-05-12 21:08:27 +02:00
|
|
|
"fmt"
|
2019-05-12 19:05:56 +02:00
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2019-11-23 19:46:31 +01:00
|
|
|
func runServer(listenAddr string) error {
|
|
|
|
serverSocket, err := net.Listen("tcp", listenAddr)
|
2019-05-12 19:05:56 +02:00
|
|
|
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 19:05:56 +02:00
|
|
|
}
|
2019-05-12 21:08:27 +02:00
|
|
|
logger.Infof("Now listening for incoming connections.\n")
|
|
|
|
defer serverSocket.Close()
|
2019-05-12 19:05:56 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|