68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
package net
|
|
|
|
import (
|
|
"net"
|
|
|
|
"git.loafle.net/commons/server-go"
|
|
)
|
|
|
|
type ServerHandler interface {
|
|
server.ServerHandler
|
|
|
|
OnError(serverCtx server.ServerCtx, conn net.Conn, status int, reason error)
|
|
|
|
RegisterServlet(servlet Servlet)
|
|
Servlet(serverCtx server.ServerCtx, conn net.Conn) Servlet
|
|
}
|
|
|
|
type ServerHandlers struct {
|
|
server.ServerHandlers
|
|
|
|
servlet Servlet
|
|
}
|
|
|
|
func (sh *ServerHandlers) Init(serverCtx server.ServerCtx) error {
|
|
if err := sh.ServerHandlers.Init(serverCtx); nil != err {
|
|
return err
|
|
}
|
|
|
|
if nil != sh.servlet {
|
|
if err := sh.servlet.Init(serverCtx); nil != err {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (sh *ServerHandlers) Destroy(serverCtx server.ServerCtx) {
|
|
if nil != sh.servlet {
|
|
sh.servlet.Destroy(serverCtx)
|
|
}
|
|
|
|
sh.ServerHandlers.Destroy(serverCtx)
|
|
}
|
|
|
|
func (sh *ServerHandlers) OnError(serverCtx server.ServerCtx, conn net.Conn, status int, reason error) {
|
|
}
|
|
|
|
func (sh *ServerHandlers) RegisterServlet(servlet Servlet) {
|
|
sh.servlet = servlet
|
|
}
|
|
|
|
func (sh *ServerHandlers) Servlet(serverCtx server.ServerCtx, conn net.Conn) Servlet {
|
|
return sh.servlet
|
|
}
|
|
|
|
func (sh *ServerHandlers) Validate() error {
|
|
if err := sh.ServerHandlers.Validate(); nil != err {
|
|
return err
|
|
}
|
|
|
|
if 0 >= sh.Concurrency {
|
|
sh.Concurrency = 0
|
|
}
|
|
|
|
return nil
|
|
}
|