Hello, I have this function: // Read a message from a stream func ReadFromStream(rd io.Reader) (Message, error) { result := Message{} // read the first nine bytes only // (mtype + length) buf := make([]byte, 9) read, err := rd.Read(buf) if err != nil { return result, err } if read < 9 { // we didn't read a full header. Well, shit. return result, InputTooShort }
result.MType = buf[0] contentLen := binary.LittleEndian.Uint64(buf[1:]) result.Content = make([]byte, contentLen) read, err = rd.Read(result.Content) if err != nil { return result, err } if read < int(contentLen) { return result, InputTooShort } return result, nil } It's meant to first read a nine-byte header (8 bits of a type field followed by a 64 bit length). In theory, it should work fine, but it always immediately returns InputTooShort (right at the first check). A bufio *might* work for this, however, I'm not confident that it will respect the deadline set on the connection. Thanks for the attention, almaember P.S. This is my system: [almaember@manjarocado ~]$ uname -a Linux manjarocado 5.13.19-2-MANJARO #1 SMP PREEMPT Sun Sep 19 21:31:53 UTC 2021 x86_64 GNU/Linux [almaember@manjarocado ~]$ go version go version go1.17.3 linux/amd64 -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3ea0fe76-f31b-4a49-afcb-5f0e611e3e4dn%40googlegroups.com.