"feat(socket): 添加跨域请求处理并集成enum依赖,优化TCP连接数据注入"
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/panjf2000/gnet/v2"
|
||||
"github.com/panjf2000/gnet/v2/pkg/logging"
|
||||
"blazing/common/data/entity"
|
||||
)
|
||||
|
||||
func (s *Server) Boot() error {
|
||||
@@ -35,19 +36,18 @@ func (s *Server) OnBoot(eng gnet.Engine) gnet.Action {
|
||||
|
||||
func (s *Server) OnTraffic(conn gnet.Conn) (action gnet.Action) {
|
||||
|
||||
|
||||
conn.SetContext(entity.NewClientData())//注入data
|
||||
if s.network == "tcp" {
|
||||
return s.handleTcp(conn)
|
||||
}
|
||||
|
||||
|
||||
|
||||
return gnet.None
|
||||
}
|
||||
|
||||
|
||||
func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
|
||||
|
||||
for {
|
||||
|
||||
data, err := s.codec.Decode(conn)
|
||||
if err != nil {
|
||||
break
|
||||
@@ -73,11 +73,11 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) {
|
||||
}
|
||||
|
||||
func (s *Server) parser(c gnet.Conn, line []byte) {
|
||||
|
||||
//todo 这里待实现注入player实体
|
||||
s.handler.Handle(line)
|
||||
}
|
||||
func (s *Server) Start() {
|
||||
|
||||
|
||||
err := gnet.Run(s, s.network+"://"+s.addr, gnet.WithMulticore(s.multicore))
|
||||
logging.Infof("server exits with error: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user