Skip to content

Commit

Permalink
remove sta
Browse files Browse the repository at this point in the history
  • Loading branch information
lizs committed Jul 13, 2018
1 parent a11ee60 commit 1552b96
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type Client struct {
Node
session *Session
autoRetryEnabled bool
sta *STAService
handler IHandler
//sta *STAService
handler IHandler
}

func (c *Client) OnOpen(s *Session) {
Expand Down
122 changes: 61 additions & 61 deletions sta.go
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
package gomsg

import (
"log"
)
// import (
// "log"
// )

type rsp struct {
session *Session
serial uint16
en int16
body []byte
}
// type rsp struct {
// session *Session
// serial uint16
// en int16
// body []byte
// }

type push struct {
session *Session
body []byte
}
// type push struct {
// session *Session
// body []byte
// }

type req struct {
session *Session
serial uint16
body []byte
}
// type req struct {
// session *Session
// serial uint16
// body []byte
// }

// Ret response chan
type Ret struct {
session *Session
serial uint16
ret *Result
}
// // Ret response chan
// type Ret struct {
// session *Session
// serial uint16
// ret *Result
// }

// NewRet new ret
func NewRet(s *Session, serial uint16, ret *Result) *Ret {
return &Ret{session: s, serial: serial, ret: ret}
}
// // NewRet new ret
// func NewRet(s *Session, serial uint16, ret *Result) *Ret {
// return &Ret{session: s, serial: serial, ret: ret}
// }

// STAService sta service
type STAService struct {
rsp chan *rsp
}
// // STAService sta service
// type STAService struct {
// rsp chan *rsp
// }

var sta *STAService
// var sta *STAService

// STA STA instance
func STA() *STAService {
if sta == nil {
sta = &STAService{
rsp: make(chan *rsp, 10000),
}
}
// // STA STA instance
// func STA() *STAService {
// if sta == nil {
// sta = &STAService{
// rsp: make(chan *rsp, 10000),
// }
// }

return sta
}
// return sta
// }

func (s *STAService) startImp() {
defer Recover()
// func (s *STAService) startImp() {
// defer Recover()

for {
select {
case rsp := <-s.rsp:
req, exists := rsp.session.reqPool[rsp.serial]
if !exists {
log.Printf("%d not exist in req pool.\n", rsp.serial)
return
}
// for {
// select {
// case rsp := <-s.rsp:
// req, exists := rsp.session.reqPool[rsp.serial]
// if !exists {
// log.Printf("%d not exist in req pool.\n", rsp.serial)
// return
// }

delete(rsp.session.reqPool, rsp.serial)
req <- &Result{En: rsp.en, Data: rsp.body}
}
}
}
// delete(rsp.session.reqPool, rsp.serial)
// req <- &Result{En: rsp.en, Data: rsp.body}
// }
// }
// }

// Start start the STA service
func (s *STAService) Start() {
go s.startImp()
}
// // Start start the STA service
// func (s *STAService) Start() {
// go s.startImp()
// }

0 comments on commit 1552b96

Please sign in to comment.