cratetorrent icon indicating copy to clipboard operation
cratetorrent copied to clipboard

Make cross-platform

Open vimpunk opened this issue 4 years ago • 3 comments

There's really no need to make cratetorrent Linux-only. The only places that rely on platform specific APIs are:

  • https://github.com/mandreyel/cratetorrent/blob/master/cratetorrent/src/disk/io/file.rs#L83
  • https://github.com/mandreyel/cratetorrent/blob/master/cratetorrent/src/disk/io/file.rs#L141
  • and uses of /tmp in tests an examples.

The real issue is the first two. The solution is very simple: feature gate those methods of TorrentFile behind a Linux flag, and fallback to coalescing buffers and issuing a single write call for other platforms.

[update]: It may actually be better to create a fallback of the Piece::write method instead of the lower level TorrentFile::write method.

This is because the current piece write method allocates a temporary buffer of iovecs, which is only needed for the pwritev syscall. However, if we're coalescing buffers and issuing a single write, we can skip the iovecs allocation step and save an allocation and other additional logic. A little more work for better performance.

vimpunk avatar Dec 22 '20 19:12 vimpunk

I presume something resembling preadv could be built on top of Overlapped IO on Windows, but I'm not sure it would worth it.

ExceptionallyHandsome avatar Dec 23 '20 17:12 ExceptionallyHandsome

That could be a future optimization for sure, but I think for now something simpler is enough. Besides, that solution would not fix incompatibility with mac/darwin/bsd, so someting more generic that is easy to maintain is better for now.

vimpunk avatar Dec 30 '20 14:12 vimpunk

Actually, Write::write_vectored should be able to replace it entirely. I'll send you a PR tomorrow.

ExceptionallyHandsome avatar Jan 01 '21 23:01 ExceptionallyHandsome