Reorganized package tree and added doc comments

This commit is contained in:
Sasha Koshka
2023-05-26 01:18:16 -04:00
parent c300567c0c
commit 60e5a1c729
11 changed files with 48 additions and 44 deletions

View File

@@ -0,0 +1,34 @@
package srvhnakra
import "log"
import "fmt"
import "net"
import "crypto/tls"
import "hnakra/router"
import "hnakra/config"
type Server struct {
underlying net.Listener
Config config.Config
Router *router.Router
}
func (server *Server) ListenAndServe () (err error) {
server.underlying, err = tls.Listen (
"tcp", fmt.Sprint(":", server.Config.RouterPort()),
config.TLSConfigFor(server.Config))
if err != nil { return err }
log.Println(".// router on", server.underlying.Addr())
for {
conn, err := server.underlying.Accept()
if err != nil { return err }
log.Println("-=E incoming connection from", conn.RemoteAddr())
server.Router.Accept(conn)
}
}
func (server *Server) Close () error {
return server.underlying.Close()
}