-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
// } |