There's a lot of blocking IO happening. This was mostly a hack to get things working, but not idea, since I spawn a new thread for each file/paste.
To make this feasible, need to switch to a proper event loop (e.g.:
calloop
?).
So far the best approach seems to be:
- Create a file descriptor with memfd.
- Encode the png into it, then seal it.
- Write to the file with
sendfile
.- When pasting, also write to the fd with
sendfile
.Need to write an adaptor that wraps sendfile into a Future.
Writing to files async is not really feasible, so writing to the file will always happen on a separate thread.
File writes are always blocking on Linux (apparently it's a POSIX thing).
I can spawn a child that does writes to a file. I need to handle the memfd to the child (e.g.: don't stream data to the child, that would be wasteful). Communicating with the child can be entirely non blocking.