|
|
|
@ -41,6 +41,7 @@ type ServerCommon struct {
|
|
|
|
|
maxHeartbeatLostSeconds int64
|
|
|
|
|
sequenceDe func([]byte) (interface{}, error)
|
|
|
|
|
sequenceEn func(interface{}) ([]byte, error)
|
|
|
|
|
showError bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewServer() Server {
|
|
|
|
@ -64,6 +65,11 @@ func NewServer() Server {
|
|
|
|
|
}
|
|
|
|
|
return &server
|
|
|
|
|
}
|
|
|
|
|
func (s *ServerCommon) ShowError(std bool) {
|
|
|
|
|
s.mu.Lock()
|
|
|
|
|
s.showError = std
|
|
|
|
|
s.mu.Unlock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *ServerCommon) Stop() error {
|
|
|
|
|
if !s.alive.Load().(bool) {
|
|
|
|
@ -184,7 +190,9 @@ func (s *ServerCommon) acceptTU() {
|
|
|
|
|
}
|
|
|
|
|
conn, err := s.listener.Accept()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("error accept:", err)
|
|
|
|
|
if s.showError {
|
|
|
|
|
fmt.Println("error accept:", err)
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
var id string
|
|
|
|
@ -274,7 +282,9 @@ func (s *ServerCommon) loadMessage() {
|
|
|
|
|
//fmt.Println("received:", float64(time.Now().UnixNano()-nowd)/1000000)
|
|
|
|
|
msg, err := s.sequenceDe(cc.msgDe(cc.SecretKey, data.Msg))
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("server decode data error", err)
|
|
|
|
|
if s.showError {
|
|
|
|
|
fmt.Println("server decode data error", err)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//fmt.Println("decoded:", float64(time.Now().UnixNano()-nowd)/1000000)
|
|
|
|
@ -405,6 +415,8 @@ func (s *ServerCommon) sendWait(c *ClientConn, msg TransferMsg, timeout time.Dur
|
|
|
|
|
close(data.Reply)
|
|
|
|
|
s.noFinSyncMsgPool.Delete(data.TransferMsg.ID)
|
|
|
|
|
return Message{}, os.ErrDeadlineExceeded
|
|
|
|
|
case <-s.stopCtx.Done():
|
|
|
|
|
return Message{}, errors.New("Service shutdown")
|
|
|
|
|
case msg, ok := <-data.Reply:
|
|
|
|
|
if !ok {
|
|
|
|
|
return msg, os.ErrInvalid
|
|
|
|
@ -434,6 +446,8 @@ func (s *ServerCommon) sendCtx(c *ClientConn, msg TransferMsg, ctx context.Conte
|
|
|
|
|
close(data.Reply)
|
|
|
|
|
s.noFinSyncMsgPool.Delete(data.TransferMsg.ID)
|
|
|
|
|
return Message{}, os.ErrClosed
|
|
|
|
|
case <-s.stopCtx.Done():
|
|
|
|
|
return Message{}, errors.New("Service shutdown")
|
|
|
|
|
case msg, ok := <-data.Reply:
|
|
|
|
|
if !ok {
|
|
|
|
|
return msg, os.ErrInvalid
|
|
|
|
|