Skip to content

Proposal: Reduce dependency on file descriptors #311

Open
@LasseBlaauwbroek

Description

@LasseBlaauwbroek

Pycapnp mostly works by passing file descriptors into the capnproto c++ library. This causes some problems:

To remedy this, I propose that instead of passing file descriptors to capnproto, we create wrappers around Python's IO facilities.

  • For synchronous file operations, we write a subclass of kj::InputStream and kj::OutputStream that wraps a Python file object
    • For synchronous socket operations, one can obtain a file-like object by calling socket.makefile. (This would also work with ssl.SSLSocket)
  • For asyncio socket operations, we write a subclass of kj::AsyncInputStream and kj:AsyncOutputStream that wraps a StreamReader and StreamWriter.
  • For asyncio file operations, it might be possible to use aiofile or aiofiles with the same interface as the previous point. To be investigated.

With these facilities, all classes like TwoPartyClient and TwoPartyServer will be modified to receive one of these wrapper classes. That should resolve all of the aforementioned problems.

A potential downside is that everything might slow down, because read and write operations have to be routed through the Python interpreter. I haven't measured the impact of this. If this is a problem, I guess we can also keep the file descriptor API (with it's known deficiencies). Downside of this, is that the file descriptor API requires a fairly large amount of code to work (see asyncProvider.cpp in #310)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions