set deadline
This commit is contained in:
@@ -62,6 +62,7 @@ func (m *CartTCPClient) Connect() error {
|
||||
|
||||
func (m *CartTCPClient) SendPacket(messageType uint32, id CartId, data []byte) error {
|
||||
err := m.Connect()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -75,6 +76,7 @@ func (m *CartTCPClient) SendPacket(messageType uint32, id CartId, data []byte) e
|
||||
return err
|
||||
}
|
||||
_, err = m.Conn.Write(data)
|
||||
m.Conn.SetDeadline(time.Now().Add(time.Second * 10))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -95,7 +97,7 @@ func (m *CartTCPClient) Call(messageType uint32, id CartId, responseType uint32,
|
||||
select {
|
||||
case ret := <-packetChan:
|
||||
return &ret, nil
|
||||
case <-time.After(time.Second):
|
||||
case <-time.After(time.Second * 10):
|
||||
return nil, fmt.Errorf("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ func (m *TCPClient) SendPacket(messageType uint32, data []byte) error {
|
||||
return m.HandleConnectionError(err)
|
||||
}
|
||||
_, err = m.Conn.Write(data)
|
||||
m.Conn.SetDeadline(time.Now().Add(time.Second * 10))
|
||||
return m.HandleConnectionError(err)
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ func (m *TCPClient) Call(messageType uint32, responseType uint32, data []byte) (
|
||||
select {
|
||||
case ret := <-packetChan:
|
||||
return &ret, nil
|
||||
case <-time.After(time.Second):
|
||||
case <-time.After(time.Second * 10):
|
||||
return nil, fmt.Errorf("timeout")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user