hashicorp / yamux

Golang connection multiplexing library
Mozilla Public License 2.0
2.19k stars 232 forks source link

Remove unnecessary for loop in Session.send() #98

Closed jacobvosmaer closed 2 years ago

jacobvosmaer commented 2 years ago

This removes a for loop around io.Writer.Write() calls in session.send(). The loop looks like what you would write in C when making write(2) syscalls. With C and write(2), you need to account for partial writes and call write(2) more than once. This is not how Go's io.Writer works. The io.Writer contract clearly states that "Write must return a non-nil error if it returns n < len(p)". Dealing with partial writes is the responsibility of implementations of io.Writer, not that of callers.

Removing the for loop makes the code simpler and more idiomatic.

hashicorp-cla commented 2 years ago

CLA assistant check
All committers have signed the CLA.

jefferai commented 2 years ago

Thanks!