mirror of https://github.com/python/cpython
gh-103673: Add missing ForkingUnixStreamServer and ForkingUnixDatagramServer socketservers (#103674)
sockserver gains ForkingUnixStreamServer and ForkingUnixDatagramServer classes for consistency with all of the others. Ironically these existed but were buried in our test suite. Addresses #103673 <!-- gh-issue-number: gh-103673 --> * Issue: gh-103673 <!-- /gh-issue-number --> --------- Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
209a0a7655
commit
d94b3a6f45
|
@ -140,9 +140,16 @@ server is the address family.
|
|||
ForkingUDPServer
|
||||
ThreadingTCPServer
|
||||
ThreadingUDPServer
|
||||
ForkingUnixStreamServer
|
||||
ForkingUnixDatagramServer
|
||||
ThreadingUnixStreamServer
|
||||
ThreadingUnixDatagramServer
|
||||
|
||||
These classes are pre-defined using the mix-in classes.
|
||||
|
||||
.. versionadded:: 3.12
|
||||
The ``ForkingUnixStreamServer`` and ``ForkingUnixDatagramServer`` classes
|
||||
were added.
|
||||
|
||||
To implement a service, you must derive a class from :class:`BaseRequestHandler`
|
||||
and redefine its :meth:`~BaseRequestHandler.handle` method.
|
||||
|
|
|
@ -141,6 +141,8 @@ if hasattr(socket, "AF_UNIX"):
|
|||
__all__.extend(["UnixStreamServer","UnixDatagramServer",
|
||||
"ThreadingUnixStreamServer",
|
||||
"ThreadingUnixDatagramServer"])
|
||||
if hasattr(os, "fork"):
|
||||
__all__.extend(["ForkingUnixStreamServer", "ForkingUnixDatagramServer"])
|
||||
|
||||
# poll/select have the advantage of not requiring any extra file descriptor,
|
||||
# contrarily to epoll/kqueue (also, they require a single syscall).
|
||||
|
@ -727,6 +729,11 @@ if hasattr(socket, 'AF_UNIX'):
|
|||
|
||||
class ThreadingUnixDatagramServer(ThreadingMixIn, UnixDatagramServer): pass
|
||||
|
||||
if hasattr(os, "fork"):
|
||||
class ForkingUnixStreamServer(ForkingMixIn, UnixStreamServer): pass
|
||||
|
||||
class ForkingUnixDatagramServer(ForkingMixIn, UnixDatagramServer): pass
|
||||
|
||||
class BaseRequestHandler:
|
||||
|
||||
"""Base class for request handler classes.
|
||||
|
|
|
@ -47,14 +47,6 @@ def receive(sock, n, timeout=test.support.SHORT_TIMEOUT):
|
|||
else:
|
||||
raise RuntimeError("timed out on %r" % (sock,))
|
||||
|
||||
if HAVE_UNIX_SOCKETS and HAVE_FORKING:
|
||||
class ForkingUnixStreamServer(socketserver.ForkingMixIn,
|
||||
socketserver.UnixStreamServer):
|
||||
pass
|
||||
|
||||
class ForkingUnixDatagramServer(socketserver.ForkingMixIn,
|
||||
socketserver.UnixDatagramServer):
|
||||
pass
|
||||
|
||||
@test.support.requires_fork()
|
||||
@contextlib.contextmanager
|
||||
|
@ -211,7 +203,7 @@ class SocketServerTest(unittest.TestCase):
|
|||
@requires_forking
|
||||
def test_ForkingUnixStreamServer(self):
|
||||
with simple_subprocess(self):
|
||||
self.run_server(ForkingUnixStreamServer,
|
||||
self.run_server(socketserver.ForkingUnixStreamServer,
|
||||
socketserver.StreamRequestHandler,
|
||||
self.stream_examine)
|
||||
|
||||
|
@ -247,7 +239,7 @@ class SocketServerTest(unittest.TestCase):
|
|||
@requires_unix_sockets
|
||||
@requires_forking
|
||||
def test_ForkingUnixDatagramServer(self):
|
||||
self.run_server(ForkingUnixDatagramServer,
|
||||
self.run_server(socketserver.ForkingUnixDatagramServer,
|
||||
socketserver.DatagramRequestHandler,
|
||||
self.dgram_examine)
|
||||
|
||||
|
|
|
@ -160,6 +160,7 @@ Brice Berna
|
|||
Olivier Bernard
|
||||
Vivien Bernet-Rollande
|
||||
Maxwell Bernstein
|
||||
Jay Berry
|
||||
Eric Beser
|
||||
Steven Bethard
|
||||
Stephen Bevan
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
:mod:`socketserver` gains ``ForkingUnixStreamServer`` and
|
||||
``ForkingUnixDatagramServer`` classes. Patch by Jay Berry.
|
Loading…
Reference in New Issue