diff --git a/protocol/tcpsocket.go b/protocol/tcpsocket.go index 88eb84e..441072b 100644 --- a/protocol/tcpsocket.go +++ b/protocol/tcpsocket.go @@ -109,3 +109,23 @@ func TCPReadAmount(conn net.Conn, amount int) ([]byte, bool) { return reply, true } + +// Read an amount and dont log errors if we fail to read from the socket +func TCPReadAmountBlind(conn net.Conn, amount int) ([]byte, bool) { + reply := make([]byte, amount) + totalRead := 0 + + // keep reading until we hit the desired amount (or an error occurs) + for totalRead < amount { + count, err := conn.Read(reply[totalRead:]) + if err != nil { + return nil, false + } + if count == 0 { + return nil, false + } + totalRead += count + } + + return reply, true +}