ws icon indicating copy to clipboard operation
ws copied to clipboard

why does conn.Write ignoring the number bytes written?

Open kant777 opened this issue 3 years ago • 2 comments

Hi,

why does conn.Write ignoring the number bytes written here https://github.com/gobwas/ws/blob/master/write.go#L95 ? It seems to me that there is no guarantee net.Conn will write all the byes in one write call. if so, shouldn't the following function return both number of bytes and the error so the application can create ws continuation frames depending on the number of bytes written?

func WriteFrame(w io.Writer, f Frame) error {
	err := WriteHeader(w, f.Header)
	if err != nil {
		return err
	}
	_, err = w.Write(f.Payload)
	return err
}

kant777 avatar Mar 07 '22 01:03 kant777

while looking at the code I was wondering the same thing :)

timofriedlberlin avatar May 02 '23 14:05 timofriedlberlin

No idea why it's written that way, now it's like this for historical reasons (we don't plan 2.x for now).

As a fix we can compare n with f.Payload and if they don't match - return an error.

cristaloleg avatar May 02 '23 16:05 cristaloleg