run on x86 for a while
This commit is contained in:
@@ -25,14 +25,14 @@ func CartDial(address string) (*CartClient, error) {
|
||||
}
|
||||
|
||||
func (c *Client) Close() {
|
||||
c.Conn.Close()
|
||||
c.PersistentConnection.Close()
|
||||
}
|
||||
|
||||
type CartTCPClient struct {
|
||||
*PersistentConnection
|
||||
sendMux sync.Mutex
|
||||
ErrorCount int
|
||||
address string
|
||||
PersistentConnection *PersistentConnection
|
||||
sendMux sync.Mutex
|
||||
ErrorCount int
|
||||
address string
|
||||
*CartPacketQueue
|
||||
}
|
||||
|
||||
@@ -52,31 +52,31 @@ func NewCartTCPClient(address string) (*CartTCPClient, error) {
|
||||
func (m *CartTCPClient) SendPacket(messageType CartMessage, id CartId, data []byte) error {
|
||||
m.sendMux.Lock()
|
||||
defer m.sendMux.Unlock()
|
||||
m.Conn.Write(header[:])
|
||||
err := binary.Write(m.Conn, binary.LittleEndian, CartPacket{
|
||||
m.PersistentConnection.Conn.Write(header[:])
|
||||
err := binary.Write(m.PersistentConnection, binary.LittleEndian, CartPacket{
|
||||
Version: CurrentPacketVersion,
|
||||
MessageType: messageType,
|
||||
DataLength: uint32(len(data)),
|
||||
Id: id,
|
||||
})
|
||||
if err != nil {
|
||||
return m.HandleConnectionError(err)
|
||||
return m.PersistentConnection.HandleConnectionError(err)
|
||||
}
|
||||
_, err = m.Conn.Write(data)
|
||||
return m.HandleConnectionError(err)
|
||||
_, err = m.PersistentConnection.Write(data)
|
||||
return m.PersistentConnection.HandleConnectionError(err)
|
||||
}
|
||||
|
||||
func (m *CartTCPClient) Call(messageType CartMessage, id CartId, responseType CartMessage, data []byte) (*CallResult, error) {
|
||||
packetChan := m.Expect(responseType, id)
|
||||
err := m.SendPacket(messageType, id, data)
|
||||
if err != nil {
|
||||
return nil, m.HandleConnectionError(err)
|
||||
return nil, m.PersistentConnection.HandleConnectionError(err)
|
||||
}
|
||||
select {
|
||||
case ret := <-packetChan:
|
||||
return &ret, nil
|
||||
case <-time.After(time.Second):
|
||||
log.Printf("Timeout waiting for cart response to message type %d\n", responseType)
|
||||
return nil, m.HandleConnectionError(fmt.Errorf("timeout"))
|
||||
return nil, m.PersistentConnection.HandleConnectionError(fmt.Errorf("timeout"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user