crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.21k stars 1.61k forks source link

Extract `#system_read` and `#system_write` for `FileDescriptor` and `Socket` #14626

Closed straight-shoota closed 1 month ago

straight-shoota commented 1 month ago

Currently, individual system implementations of System::FileDescriptor and System::Socket implement IO#unbuffered_read and IO#unbuffered_write directly. This patch pulls the implementation up to be shared between all platforms, and instead delegates to #system_read and #system_write.

#unbuffered_write is now responsible for ensuring that the entire content of the slice is written, calling system_write multiple times if necessary. (Looks like this wasn't implemented correctly in Socket on Windows before)

This is a simplification step in preparation for a bigger refactoring which will delegate #system_read and #system_write to the event loop (https://github.com/crystal-lang/rfcs/pull/7).