new server structure

This commit is contained in:
aler9
2020-12-08 21:15:02 +01:00
parent 927511d81e
commit c7f6d77392
5 changed files with 118 additions and 133 deletions

View File

@@ -9,8 +9,8 @@ import (
var DefaultServerConf = ServerConf{}
// Serve starts a server on the given address.
func Serve(address string, handler func(sc *ServerConn) ServerConnHandler) (*Server, error) {
return DefaultServerConf.Serve(address, handler)
func Serve(address string) (*Server, error) {
return DefaultServerConf.Serve(address)
}
// ServerConf allows to configure a Server.
@@ -36,7 +36,7 @@ type ServerConf struct {
}
// Serve starts a server on the given address.
func (c ServerConf) Serve(address string, handler func(sc *ServerConn) ServerConnHandler) (*Server, error) {
func (c ServerConf) Serve(address string) (*Server, error) {
if c.ReadTimeout == 0 {
c.ReadTimeout = 10 * time.Second
}
@@ -63,11 +63,7 @@ func (c ServerConf) Serve(address string, handler func(sc *ServerConn) ServerCon
s := &Server{
conf: c,
listener: listener,
handler: handler,
}
s.wg.Add(1)
go s.run()
return s, nil
}