ing
This commit is contained in:
parent
53a7e28c86
commit
b0aa331648
|
@ -124,13 +124,13 @@ func handleServer(s *server) {
|
||||||
|
|
||||||
var socketID string
|
var socketID string
|
||||||
socketHandler := s.sh.GetSocketHandler()
|
socketHandler := s.sh.GetSocketHandler()
|
||||||
|
socketCTX := socketHandler.SocketContext(s.ctx)
|
||||||
|
|
||||||
if socketID = socketHandler.Handshake(s.ctx, conn); "" == socketID {
|
if socketID = socketHandler.Handshake(socketCTX, conn); "" == socketID {
|
||||||
logging.Logger().Error(fmt.Sprintf("Server: Handshake err addr[%s] %v", conn.RemoteAddr(), conn))
|
logging.Logger().Error(fmt.Sprintf("Server: Handshake err addr[%s] %v", conn.RemoteAddr(), conn))
|
||||||
conn.Close()
|
conn.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
socketCTX := socketHandler.SocketContext(s.ctx)
|
|
||||||
soc := newSocket(socketHandler, socketCTX, conn, socketID)
|
soc := newSocket(socketHandler, socketCTX, conn, socketID)
|
||||||
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))
|
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ type SocketHandler interface {
|
||||||
Init(serverCTX ServerContext) error
|
Init(serverCTX ServerContext) error
|
||||||
// Handshake do handshake client and server
|
// Handshake do handshake client and server
|
||||||
// id is identity of client socket. if id is "", disallow connection
|
// id is identity of client socket. if id is "", disallow connection
|
||||||
Handshake(serverCTX ServerContext, conn net.Conn) (id string)
|
Handshake(socketCTX SocketContext, conn net.Conn) (id string)
|
||||||
// OnConnect invoked when client is connected
|
// OnConnect invoked when client is connected
|
||||||
// If you override ths method, must call
|
// If you override ths method, must call
|
||||||
//
|
//
|
||||||
|
|
|
@ -24,20 +24,20 @@ type SocketHandlers struct {
|
||||||
sockets map[string]Socket
|
sockets map[string]Socket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) SocketContext(serverCTX ServerContext) SocketContext {
|
||||||
|
return newSocketContext(serverCTX)
|
||||||
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) Init(serverCTX ServerContext) error {
|
func (sh *SocketHandlers) Init(serverCTX ServerContext) error {
|
||||||
sh.sockets = make(map[string]Socket)
|
sh.sockets = make(map[string]Socket)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) Handshake(serverCTX ServerContext, conn net.Conn) (id string) {
|
func (sh *SocketHandlers) Handshake(socketCTX SocketContext, conn net.Conn) (id string) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) SocketContext(serverCTX ServerContext) SocketContext {
|
|
||||||
return newSocketContext(serverCTX)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sh *SocketHandlers) OnConnect(soc Socket) {
|
func (sh *SocketHandlers) OnConnect(soc Socket) {
|
||||||
// no op
|
// no op
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ func (sh *SocketHandlers) Destroy() {
|
||||||
func (sh *SocketHandlers) GetSocket(id string) Socket {
|
func (sh *SocketHandlers) GetSocket(id string) Socket {
|
||||||
return sh.sockets[id]
|
return sh.sockets[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) GetSockets() map[string]Socket {
|
func (sh *SocketHandlers) GetSockets() map[string]Socket {
|
||||||
return sh.sockets
|
return sh.sockets
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user