gobwas / ws

Tiny WebSocket library for Go.
MIT License
6.09k stars 373 forks source link

why does conn.Write ignoring the number bytes written? #150

Open kant777 opened 2 years ago

kant777 commented 2 years ago

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
}
timo-klarshift commented 1 year ago

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

cristaloleg commented 1 year ago

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.