Skip to content

Commit

Permalink
Drop dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Oct 20, 2020
1 parent a501039 commit ebeecdb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 96 deletions.
29 changes: 1 addition & 28 deletions aiohttp/tcp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
from contextlib import suppress
from typing import Optional # noqa

__all__ = ('tcp_keepalive', 'tcp_nodelay', 'tcp_cork')


if hasattr(socket, 'TCP_CORK'): # pragma: no cover
CORK = socket.TCP_CORK # type: Optional[int]
elif hasattr(socket, 'TCP_NOPUSH'): # pragma: no cover
CORK = socket.TCP_NOPUSH # type: ignore
else: # pragma: no cover
CORK = None
__all__ = ('tcp_keepalive', 'tcp_nodelay')


if hasattr(socket, 'SO_KEEPALIVE'):
Expand Down Expand Up @@ -42,22 +34,3 @@ def tcp_nodelay(transport: asyncio.Transport, value: bool) -> None:
with suppress(OSError):
sock.setsockopt(
socket.IPPROTO_TCP, socket.TCP_NODELAY, value)


def tcp_cork(transport: asyncio.Transport, value: bool) -> None:
sock = transport.get_extra_info('socket')

if CORK is None:
return

if sock is None:
return

if sock.family not in (socket.AF_INET, socket.AF_INET6):
return

value = bool(value)

with suppress(OSError):
sock.setsockopt(
socket.IPPROTO_TCP, CORK, value)
69 changes: 1 addition & 68 deletions tests/test_tcp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from aiohttp.tcp_helpers import CORK, tcp_cork, tcp_nodelay
from aiohttp.tcp_helpers import tcp_nodelay

has_ipv6 = socket.has_ipv6
if has_ipv6:
Expand Down Expand Up @@ -75,70 +75,3 @@ def test_tcp_nodelay_enable_no_socket() -> None:
transport = mock.Mock()
transport.get_extra_info.return_value = None
tcp_nodelay(transport, True)


# cork


@pytest.mark.skipif(CORK is None, reason="TCP_CORK or TCP_NOPUSH required")
def test_tcp_cork_enable() -> None:
transport = mock.Mock()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
transport.get_extra_info.return_value = s
tcp_cork(transport, True)
assert s.getsockopt(socket.IPPROTO_TCP, CORK)


@pytest.mark.skipif(CORK is None, reason="TCP_CORK or TCP_NOPUSH required")
def test_set_cork_enable_and_disable() -> None:
transport = mock.Mock()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
transport.get_extra_info.return_value = s
tcp_cork(transport, True)
assert s.getsockopt(socket.IPPROTO_TCP, CORK)
tcp_cork(transport, False)
assert not s.getsockopt(socket.IPPROTO_TCP, CORK)


@pytest.mark.skipif(not has_ipv6, reason="IPv6 is not available")
@pytest.mark.skipif(CORK is None, reason="TCP_CORK or TCP_NOPUSH required")
def test_set_cork_enable_ipv6() -> None:
transport = mock.Mock()
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
transport.get_extra_info.return_value = s
tcp_cork(transport, True)
assert s.getsockopt(socket.IPPROTO_TCP, CORK)


@pytest.mark.skipif(not hasattr(socket, 'AF_UNIX'),
reason="requires unix sockets")
@pytest.mark.skipif(CORK is None, reason="TCP_CORK or TCP_NOPUSH required")
def test_set_cork_enable_unix() -> None:
transport = mock.Mock()
s = mock.Mock(family=socket.AF_UNIX, type=socket.SOCK_STREAM)
transport.get_extra_info.return_value = s
tcp_cork(transport, True)
assert not s.setsockopt.called


@pytest.mark.skipif(CORK is None, reason="TCP_CORK or TCP_NOPUSH required")
def test_set_cork_enable_no_socket() -> None:
transport = mock.Mock()
transport.get_extra_info.return_value = None
tcp_cork(transport, True)


@pytest.mark.skipif(CORK is None, reason="TCP_CORK or TCP_NOPUSH required")
def test_set_cork_exception() -> None:
transport = mock.Mock()
s = mock.Mock()
s.setsockopt = mock.Mock()
s.family = socket.AF_INET
s.setsockopt.side_effect = OSError
transport.get_extra_info.return_value = s
tcp_cork(transport, True)
s.setsockopt.assert_called_with(
socket.IPPROTO_TCP,
CORK,
True
)

0 comments on commit ebeecdb

Please sign in to comment.