update queue for max performance
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m1s

This commit is contained in:
matst80
2024-11-11 20:33:34 +01:00
parent 3eaa42b615
commit cd1fb91892
7 changed files with 272 additions and 171 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"encoding/binary"
"fmt"
"net"
"time"
)
@@ -94,13 +95,16 @@ func (m *TCPClient) SendPacket(messageType uint32, data []byte) error {
// }
func (m *TCPClient) Call(messageType uint32, responseType uint32, data []byte) ([]byte, error) {
packetChan := m.Expect(responseType)
err := m.SendPacket(messageType, data)
if err != nil {
return nil, err
}
packet, err := m.Expect(responseType, time.Second)
if err != nil {
return nil, err
select {
case ret := <-packetChan:
return ret, nil
case <-time.After(3 * time.Second):
return nil, fmt.Errorf("timeout")
}
return packet.Data, nil
}