Add PreHandlerClientFunc and PostHandlerClientFunc to Server struct
This commit is contained in:
parent
028dc99fc2
commit
7338bc69fa
|
@ -60,7 +60,11 @@ func CreateHandleClientFuncFromCommands(bundle *tcpcommand.CommandBundle, conf S
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
addr string
|
addr string
|
||||||
|
PreHandlerClientFunc func(client net.Conn)
|
||||||
HandleClientFunc func(client net.Conn)
|
HandleClientFunc func(client net.Conn)
|
||||||
|
// Use PostHandlerClientFunc in your HandleClientFunc if you
|
||||||
|
// use custom HandleClientFunc
|
||||||
|
PostHandlerClientFunc func(client net.Conn)
|
||||||
Exit chan bool
|
Exit chan bool
|
||||||
//
|
//
|
||||||
MessageEndRune rune
|
MessageEndRune rune
|
||||||
|
@ -74,6 +78,9 @@ type Server struct {
|
||||||
|
|
||||||
func defaultHandleClientFunc(server *Server) func(net.Conn) {
|
func defaultHandleClientFunc(server *Server) func(net.Conn) {
|
||||||
return func(client net.Conn) {
|
return func(client net.Conn) {
|
||||||
|
if server.PostHandlerClientFunc != nil {
|
||||||
|
defer server.PostHandlerClientFunc(client)
|
||||||
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
connReader := bufio.NewReader(client)
|
connReader := bufio.NewReader(client)
|
||||||
for {
|
for {
|
||||||
|
@ -184,6 +191,9 @@ loop:
|
||||||
if s.LogLevel&LogLevel_Connection > 0 {
|
if s.LogLevel&LogLevel_Connection > 0 {
|
||||||
fmt.Printf("New Connection from %s is accepted\n", newClient.RemoteAddr())
|
fmt.Printf("New Connection from %s is accepted\n", newClient.RemoteAddr())
|
||||||
}
|
}
|
||||||
|
if s.PreHandlerClientFunc != nil {
|
||||||
|
s.PreHandlerClientFunc(newClient)
|
||||||
|
}
|
||||||
go s.HandleClientFunc(newClient)
|
go s.HandleClientFunc(newClient)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user