Compare commits
No commits in common. "f51d2c713703e7acb56505e93f68a51432dc10c1" and "3964cd05b0124d866ca3d51816de6bb1b8f6ac48" have entirely different histories.
f51d2c7137
...
3964cd05b0
19
client.go
19
client.go
@ -42,7 +42,6 @@ type ClientCommon struct {
|
||||
heartbeatPeriod time.Duration
|
||||
wg stario.WaitGroup
|
||||
netType NetType
|
||||
showError bool
|
||||
skipKeyExchange bool
|
||||
useHeartBeat bool
|
||||
sequenceDe func([]byte) (interface{}, error)
|
||||
@ -202,12 +201,6 @@ func (c *ClientCommon) Heartbeat() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ClientCommon) ShowError(std bool) {
|
||||
c.mu.Lock()
|
||||
c.showError = std
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *ClientCommon) readMessage() {
|
||||
for {
|
||||
select {
|
||||
@ -228,9 +221,7 @@ func (c *ClientCommon) readMessage() {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
if c.showError {
|
||||
fmt.Println("client read error", err)
|
||||
}
|
||||
fmt.Println("client read error", err)
|
||||
c.alive.Store(false)
|
||||
c.mu.Lock()
|
||||
c.status = Status{
|
||||
@ -278,9 +269,7 @@ func (c *ClientCommon) loadMessage() {
|
||||
//transfer to Msg
|
||||
msg, err := c.sequenceDe(c.msgDe(c.SecretKey, data.Msg))
|
||||
if err != nil {
|
||||
if c.showError {
|
||||
fmt.Println("client decode data error", err)
|
||||
}
|
||||
fmt.Println("client decode data error", err)
|
||||
return
|
||||
}
|
||||
message := Message{
|
||||
@ -410,8 +399,6 @@ func (c *ClientCommon) sendWait(msg TransferMsg, timeout time.Duration) (Message
|
||||
close(data.Reply)
|
||||
c.noFinSyncMsgPool.Delete(data.TransferMsg.ID)
|
||||
return Message{}, os.ErrDeadlineExceeded
|
||||
case <-c.stopCtx.Done():
|
||||
return Message{}, errors.New("Service shutdown")
|
||||
case msg, ok := <-data.Reply:
|
||||
if !ok {
|
||||
return msg, os.ErrInvalid
|
||||
@ -433,8 +420,6 @@ func (c *ClientCommon) sendCtx(msg TransferMsg, ctx context.Context) (Message, e
|
||||
close(data.Reply)
|
||||
c.noFinSyncMsgPool.Delete(data.TransferMsg.ID)
|
||||
return Message{}, os.ErrDeadlineExceeded
|
||||
case <-c.stopCtx.Done():
|
||||
return Message{}, errors.New("Service shutdown")
|
||||
case msg, ok := <-data.Reply:
|
||||
if !ok {
|
||||
return msg, os.ErrInvalid
|
||||
|
@ -38,7 +38,6 @@ type Client interface {
|
||||
Stop() error
|
||||
StopMonitorChan() <-chan struct{}
|
||||
Status() Status
|
||||
ShowError(bool)
|
||||
|
||||
GetSequenceEn() func(interface{}) ([]byte, error)
|
||||
SetSequenceEn(func(interface{}) ([]byte, error))
|
||||
|
20
server.go
20
server.go
@ -41,7 +41,6 @@ type ServerCommon struct {
|
||||
maxHeartbeatLostSeconds int64
|
||||
sequenceDe func([]byte) (interface{}, error)
|
||||
sequenceEn func(interface{}) ([]byte, error)
|
||||
showError bool
|
||||
}
|
||||
|
||||
func NewServer() Server {
|
||||
@ -65,11 +64,6 @@ 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) {
|
||||
@ -190,9 +184,7 @@ func (s *ServerCommon) acceptTU() {
|
||||
}
|
||||
conn, err := s.listener.Accept()
|
||||
if err != nil {
|
||||
if s.showError {
|
||||
fmt.Println("error accept:", err)
|
||||
}
|
||||
fmt.Println("error accept:", err)
|
||||
continue
|
||||
}
|
||||
var id string
|
||||
@ -282,9 +274,7 @@ 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 {
|
||||
if s.showError {
|
||||
fmt.Println("server decode data error", err)
|
||||
}
|
||||
fmt.Println("server decode data error", err)
|
||||
return
|
||||
}
|
||||
//fmt.Println("decoded:", float64(time.Now().UnixNano()-nowd)/1000000)
|
||||
@ -304,7 +294,7 @@ func (s *ServerCommon) loadMessage() {
|
||||
func (s *ServerCommon) sysMsg(message Message) {
|
||||
switch message.Key {
|
||||
case "bye":
|
||||
//fmt.Println("recv stop signal from client", message.ClientConn.ClientID)
|
||||
fmt.Println("recv stop signal from client", message.ClientConn.ClientID)
|
||||
if message.TransferMsg.Type == MSG_SYS_WAIT {
|
||||
message.Reply(nil)
|
||||
}
|
||||
@ -415,8 +405,6 @@ 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
|
||||
@ -446,8 +434,6 @@ 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
|
||||
|
@ -40,7 +40,6 @@ type Server interface {
|
||||
SetSequenceEn(func(interface{}) ([]byte, error))
|
||||
GetSequenceDe() func([]byte) (interface{}, error)
|
||||
SetSequenceDe(func([]byte) (interface{}, error))
|
||||
ShowError(bool)
|
||||
|
||||
HeartbeatTimeoutSec() int64
|
||||
SetHeartbeatTimeoutSec(int64)
|
||||
|
Loading…
x
Reference in New Issue
Block a user