2018-04-04 04:01:26 +00:00
|
|
|
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)
|
2018-04-04 16:51:34 +00:00
|
|
|
Servlet(serverCtx server.ServerCtx, conn net.Conn) Servlet
|
2018-04-04 04:01:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:51:34 +00:00
|
|
|
func (sh *ServerHandlers) Servlet(serverCtx server.ServerCtx, conn net.Conn) Servlet {
|
2018-04-04 04:01:26 +00:00
|
|
|
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
|
|
|
|
}
|