fs2 icon indicating copy to clipboard operation
fs2 copied to clipboard

Support reading from `ReadCursor` / writing to `WriteCursor` via `Socket`

Open armanbilge opened this issue 2 years ago • 2 comments

There are some really efficient APIs for this:

  • https://man7.org/linux/man-pages/man2/sendfile.2.html
  • https://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileChannel.html#transferTo-long-long-java.nio.channels.WritableByteChannel-
  • https://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileChannel.html#transferFrom-java.nio.channels.ReadableByteChannel-long-long-
  • https://std.in/using-sendfile-with-nodejs/

I'm fairly confident we can add a default implementation to Socket just using the Stream APIs. If so, then this opens the door for more specialized overrides on the actual implementation.

armanbilge avatar Mar 22 '23 03:03 armanbilge

@armanbilge If this issue is still relevant ,can you assign this issue to me ?

rahulrangers avatar Mar 14 '25 17:03 rahulrangers

I am thinking that in this issue

  1. we need to create two files SocketReadCursor and SocketWriteCursor which is used to read from the socket and write to socket just like the cursors in file handling.
  2. use these to override the implementation in platforms-specific files using sendfile syscall where we send the data directly from the file in disk to kernel which increases efficiency. But I am not understanding the idea of read and writecursors through sockets as these are not persistence or static as files , so idea of sequentially reading using offset seems not right to me? Am i going in right direction @armanbilge

rahulrangers avatar Mar 15 '25 18:03 rahulrangers