Change History (21)

Once this is implemented, the systemd endpoint should work with UNIX sockets. If it does, then the systemd documentation which mentions that UNIX sockets are not supported should be adjusted. Otherwise, re-open #6310 to make it work.

I've attached a patch that gets UNIX socket adoption working for adoptStreamPort and adoptStreamConnection. I've had some trouble getting adoptDatagramPort working, but if I get that going I'll attach a patch to #6954.

A couple of notes about the patch:

I've changed all the old-style exception raising to new-style. I'm happy to remove that to minimise changes, if desirable.

I haven't got any tests for adoptStreamConnection, and I couldn't find any. In my eyes I basically need to start a server outside of Twisted's vision, accept a connection, and then adopt that connection. If anyone has any advice on writing a test like this or has any similar tests, I'd be happy to have another go at it.

Yes, please do that. Smaller changes make it through review faster. Those changes will be great, just please put them into a different patch and ticket :).

Thanks!

Sure! No problem, I've attached that patch now. I have a few other syntactic changes to make to twisted.internet.unix to make it Python 3 compatible, so I might bundle them up with those and submit it.

I haven't got any tests for adoptStreamConnection, and I couldn't find any. In my eyes I basically need to start a server outside of Twisted's vision, accept a connection, and then adopt that connection. If anyone has any advice on writing a test like this or has any similar tests, I'd be happy to have another go at it.

Great! Thank you. I've added tests now and submitted a new patch. There is one note that I forgot to mention earlier, in twisted.internet.unix.Server._fromConnectedSocket(), I wasn't sure of the best place to draw a session number from, so I've set it to zero:

# self.mktemp() often returns a path which is too long to be used.
path = mktemp(suffix='.sock', dir='.')

maybe we can have

path = self.getSocketPath()
def getUnixSocketPath(self):
"""
Return a path which can be used as an Unix socket.
"""
# self.mktemp() often returns a path which is too long to be used.
path = mktemp(suffix='.sock', dir='.')

In this way we don't have to duplicate the comment and in case we find out a better way to generate unix socket path we only have to change the code in one place.

I don't know what to say about this

[peerAddress] = server.factory.peerAddresses

it works but in the other Twisted code I see that it uses

peerAddress = server.factory.peerAddresses[0]

Regarding test_ServerAddressUNIX I think that we should do the assertion synchronous.