OnConnection changed to OnConnected

This commit is contained in:
crusader 2017-09-20 12:53:06 +09:00
parent 3775bb8e38
commit 14b0aea1ca
3 changed files with 20 additions and 3 deletions

View File

@ -89,6 +89,11 @@ func (s *server) onConnection(ctx *fasthttp.RequestCtx) {
return
}
if !s._sh.OnConnection(ctx) {
ctx.Error(http.StatusText(http.StatusNotAcceptable), http.StatusNotAcceptable)
return
}
s._upgrader.Upgrade(ctx, nil, func(conn *websocket.Conn, err error) {
if err != nil {
s.onError(ctx, fasthttp.StatusInternalServerError, err)
@ -97,7 +102,7 @@ func (s *server) onConnection(ctx *fasthttp.RequestCtx) {
id := s._sh.OnIDGenerate(ctx)
soc := NewSocket(s._ctx, id, path, co, conn)
s.addSocket(soc)
s._sh.OnConnection(soc)
s._sh.OnConnected(soc)
soc.run()
})

View File

@ -12,7 +12,8 @@ type ServerHandler interface {
GetWriteBufferSize() int
GetEnableCompression() bool
OnConnection(soc Socket)
OnConnection(ctx *fasthttp.RequestCtx) bool
OnConnected(soc Socket)
OnDisconnected(soc Socket)
OnCheckOrigin(ctx *fasthttp.RequestCtx) bool
OnError(ctx *fasthttp.RequestCtx, status int, reason error)

View File

@ -29,28 +29,39 @@ type ServerHandlers struct {
func (sh *ServerHandlers) GetHandshakeTimeout() time.Duration {
return sh.HandshakeTimeout
}
func (sh *ServerHandlers) GetReadBufferSize() int {
return sh.ReadBufferSize
}
func (sh *ServerHandlers) GetWriteBufferSize() int {
return sh.WriteBufferSize
}
func (sh *ServerHandlers) GetEnableCompression() bool {
return sh.EnableCompression
}
func (sh *ServerHandlers) OnConnection(soc Socket) {
func (sh *ServerHandlers) OnConnection(ctx *fasthttp.RequestCtx) bool {
return true
}
func (sh *ServerHandlers) OnConnected(soc Socket) {
}
func (sh *ServerHandlers) OnDisconnected(soc Socket) {
}
func (sh *ServerHandlers) OnCheckOrigin(ctx *fasthttp.RequestCtx) bool {
return true
}
func (sh *ServerHandlers) OnError(ctx *fasthttp.RequestCtx, status int, reason error) {
}
func (sh *ServerHandlers) OnIDGenerate(ctx *fasthttp.RequestCtx) string {
return uuid.NewV4().String()
}