Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: UNIX server sockets #1433

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft

RFC: UNIX server sockets #1433

wants to merge 29 commits into from

Conversation

Tronic
Copy link
Contributor

@Tronic Tronic commented Mar 11, 2020

Implement high level API for UNIX server sockets, based on #279

This needs some more work but I'd like to invite others for comments at this point.

@decentral1se
Copy link
Member

Just tried to figure out how to serve a unix socket and ended up here, thanks for this effort ... I guess my only capacity to help this along is basically to bump the PR with this comment 😅 There is a whole bunch of stuff here I had no idea that should be taken care of when dealing with sockets...

@decentral1se
Copy link
Member

decentral1se commented Aug 16, 2020

Oh yeah, could also take it for a test drive! Saw the following warning when running serve_unix:

TrioDeprecationWarning: subclassing trio.SocketListener is deprecated since Trio 0.15.0; use composition or delegation instead (#1044) class UnixSocketListener(trio.SocketListener):

Seems to do the job 🌞

from functools import partial
from trio import open_nursery, open_unix_socket, run
from trio_socket import serve_unix  # gh:python-trio/trio/pull/1433

SOCK_PATH = "/tmp/temp.sock"

async def client():
    stream = await open_unix_socket(SOCK_PATH)
    async with stream:
        await stream.send_all(b"hello, world")

async def server(stream):
    async for data in stream:
        print(f"received -> {data}")

async def main():
    async with open_nursery() as server_nursery:
        await server_nursery.start(partial(serve_unix, server, SOCK_PATH))
        async with open_nursery() as client_nursery:
            client_nursery.start_soon(client)
        server_nursery.cancel_scope.cancel()

run(main)

@py-radicz
Copy link

I am also bumping this PR as I think it would be nice to have also UDS server support - thank you @Tronic + @decentral1se you saved me ton of time figuring this out

Comment on lines 217 to 220
The socket is initially created with a random token appended to its
name, and then moved over the requested name while protected by a
separate lock file. The additional names use suffixes on the
requested name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, should we try removing this?

@codecov
Copy link

codecov bot commented Sep 3, 2023

Codecov Report

Attention: 110 lines in your changes are missing coverage. Please review.

Comparison is base (78c55aa) 92.94% compared to head (99f17c5) 98.57%.

❗ Current head 99f17c5 differs from pull request most recent head 8e613a0. Consider uploading reports for the commit 8e613a0 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1433      +/-   ##
==========================================
+ Coverage   92.94%   98.57%   +5.63%     
==========================================
  Files         117      117              
  Lines       17634    17774     +140     
  Branches     3172     3174       +2     
==========================================
+ Hits        16390    17521    +1131     
+ Misses       1154      204     -950     
+ Partials       90       49      -41     
Files Coverage Δ
trio/__init__.py 100.00% <100.00%> (ø)
trio/_tests/test_highlevel_open_unix_listeners.py 38.46% <38.46%> (ø)
trio/_highlevel_open_unix_listeners.py 30.88% <30.88%> (ø)

... and 231 files with indirect coverage changes

@CoolCat467 CoolCat467 marked this pull request as draft February 20, 2024 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants