|
|
@ -45,10 +45,10 @@ type PongHandler func(string) error
|
|
|
|
type Client struct {
|
|
|
|
type Client struct {
|
|
|
|
w *sync.Mutex
|
|
|
|
w *sync.Mutex
|
|
|
|
conn LongConn
|
|
|
|
conn LongConn
|
|
|
|
platformID int
|
|
|
|
PlatformID int `json:"platformID"`
|
|
|
|
isCompress bool
|
|
|
|
IsCompress bool `json:"isCompress"`
|
|
|
|
userID string
|
|
|
|
UserID string `json:"userID"`
|
|
|
|
isBackground bool
|
|
|
|
IsBackground bool `json:"isBackground"`
|
|
|
|
ctx *UserConnContext
|
|
|
|
ctx *UserConnContext
|
|
|
|
longConnServer LongConnServer
|
|
|
|
longConnServer LongConnServer
|
|
|
|
closed bool
|
|
|
|
closed bool
|
|
|
@ -59,21 +59,21 @@ func newClient(ctx *UserConnContext, conn LongConn, isCompress bool) *Client {
|
|
|
|
return &Client{
|
|
|
|
return &Client{
|
|
|
|
w: new(sync.Mutex),
|
|
|
|
w: new(sync.Mutex),
|
|
|
|
conn: conn,
|
|
|
|
conn: conn,
|
|
|
|
platformID: utils.StringToInt(ctx.GetPlatformID()),
|
|
|
|
PlatformID: utils.StringToInt(ctx.GetPlatformID()),
|
|
|
|
isCompress: isCompress,
|
|
|
|
IsCompress: isCompress,
|
|
|
|
userID: ctx.GetUserID(),
|
|
|
|
UserID: ctx.GetUserID(),
|
|
|
|
ctx: ctx,
|
|
|
|
ctx: ctx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, isCompress bool, longConnServer LongConnServer) {
|
|
|
|
func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, isCompress bool, longConnServer LongConnServer) {
|
|
|
|
c.w = new(sync.Mutex)
|
|
|
|
c.w = new(sync.Mutex)
|
|
|
|
c.conn = conn
|
|
|
|
c.conn = conn
|
|
|
|
c.platformID = utils.StringToInt(ctx.GetPlatformID())
|
|
|
|
c.PlatformID = utils.StringToInt(ctx.GetPlatformID())
|
|
|
|
c.isCompress = isCompress
|
|
|
|
c.IsCompress = isCompress
|
|
|
|
c.userID = ctx.GetUserID()
|
|
|
|
c.UserID = ctx.GetUserID()
|
|
|
|
c.ctx = ctx
|
|
|
|
c.ctx = ctx
|
|
|
|
c.longConnServer = longConnServer
|
|
|
|
c.longConnServer = longConnServer
|
|
|
|
c.isBackground = false
|
|
|
|
c.IsBackground = false
|
|
|
|
c.closed = false
|
|
|
|
c.closed = false
|
|
|
|
c.closedErr = nil
|
|
|
|
c.closedErr = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -126,7 +126,7 @@ func (c *Client) readMessage() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (c *Client) handleMessage(message []byte) error {
|
|
|
|
func (c *Client) handleMessage(message []byte) error {
|
|
|
|
if c.isCompress {
|
|
|
|
if c.IsCompress {
|
|
|
|
var decompressErr error
|
|
|
|
var decompressErr error
|
|
|
|
message, decompressErr = c.longConnServer.DeCompress(message)
|
|
|
|
message, decompressErr = c.longConnServer.DeCompress(message)
|
|
|
|
if decompressErr != nil {
|
|
|
|
if decompressErr != nil {
|
|
|
@ -141,10 +141,10 @@ func (c *Client) handleMessage(message []byte) error {
|
|
|
|
if err := c.longConnServer.Validate(binaryReq); err != nil {
|
|
|
|
if err := c.longConnServer.Validate(binaryReq); err != nil {
|
|
|
|
return utils.Wrap(err, "")
|
|
|
|
return utils.Wrap(err, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if binaryReq.SendID != c.userID {
|
|
|
|
if binaryReq.SendID != c.UserID {
|
|
|
|
return utils.Wrap(errors.New("exception conn userID not same to req userID"), binaryReq.String())
|
|
|
|
return utils.Wrap(errors.New("exception conn userID not same to req userID"), binaryReq.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx := mcontext.WithMustInfoCtx([]string{binaryReq.OperationID, binaryReq.SendID, constant.PlatformIDToName(c.platformID), c.ctx.GetConnID()})
|
|
|
|
ctx := mcontext.WithMustInfoCtx([]string{binaryReq.OperationID, binaryReq.SendID, constant.PlatformIDToName(c.PlatformID), c.ctx.GetConnID()})
|
|
|
|
log.ZDebug(ctx, "gateway req message", "req", binaryReq.String())
|
|
|
|
log.ZDebug(ctx, "gateway req message", "req", binaryReq.String())
|
|
|
|
var messageErr error
|
|
|
|
var messageErr error
|
|
|
|
var resp []byte
|
|
|
|
var resp []byte
|
|
|
@ -173,7 +173,7 @@ func (c *Client) setAppBackgroundStatus(ctx context.Context, req Req) ([]byte, e
|
|
|
|
if messageErr != nil {
|
|
|
|
if messageErr != nil {
|
|
|
|
return nil, messageErr
|
|
|
|
return nil, messageErr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.isBackground = isBackground
|
|
|
|
c.IsBackground = isBackground
|
|
|
|
//todo callback
|
|
|
|
//todo callback
|
|
|
|
return resp, nil
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
|
|
|
@ -240,7 +240,7 @@ func (c *Client) writeBinaryMsg(resp Resp) error {
|
|
|
|
return utils.Wrap(err, "")
|
|
|
|
return utils.Wrap(err, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ = c.conn.SetWriteDeadline(writeWait)
|
|
|
|
_ = c.conn.SetWriteDeadline(writeWait)
|
|
|
|
if c.isCompress {
|
|
|
|
if c.IsCompress {
|
|
|
|
var compressErr error
|
|
|
|
var compressErr error
|
|
|
|
resultBuf, compressErr = c.longConnServer.Compress(encodedBuf)
|
|
|
|
resultBuf, compressErr = c.longConnServer.Compress(encodedBuf)
|
|
|
|
if compressErr != nil {
|
|
|
|
if compressErr != nil {
|
|
|
|