-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Get rid of legacy StreamWriter (#2623) Legacy StreamWriter as a pure proxy of the transport and the protocol is no longer needed. All of the functionalities that were behind this class has been moved to the PayloadWriter. Some changes that have to be considered that impacted during this change * TCP Operations have been isolated in a module rather than move them into the PayloadWriter * WebSocketWriter had a dependency with the StreamWriter, to get rid of that dependency the constructor has been modified to take the protocol and the transport. A next step changing the name PayLoadWriter for the StreamWriter to have consistency with the reader part, might be considered. * Add CHANGES * Fixed invalid import order * Fix test broken * Fix tcp_cork issues * Test PayloadWriter properties * Avoid return useless values for tcp_<operations> * Increase coverage http_writer * Increase coverage web_protocol
- Loading branch information
Showing
19 changed files
with
426 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Get rid of the legacy class StreamWriter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Helper methods to tune a TCP connection""" | ||
|
||
import socket | ||
from contextlib import suppress | ||
|
||
|
||
__all__ = ('tcp_keepalive', 'tcp_nodelay', 'tcp_cork') | ||
|
||
|
||
if hasattr(socket, 'TCP_CORK'): # pragma: no cover | ||
CORK = socket.TCP_CORK | ||
elif hasattr(socket, 'TCP_NOPUSH'): # pragma: no cover | ||
CORK = socket.TCP_NOPUSH | ||
else: # pragma: no cover | ||
CORK = None | ||
|
||
|
||
if hasattr(socket, 'SO_KEEPALIVE'): | ||
def tcp_keepalive(transport): | ||
sock = transport.get_extra_info('socket') | ||
if sock is not None: | ||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) | ||
else: | ||
def tcp_keepalive(transport): # pragma: no cover | ||
pass | ||
|
||
|
||
def tcp_nodelay(transport, value): | ||
sock = transport.get_extra_info('socket') | ||
|
||
if sock is None: | ||
return | ||
|
||
if sock.family not in (socket.AF_INET, socket.AF_INET6): | ||
return | ||
|
||
value = bool(value) | ||
|
||
# socket may be closed already, on windows OSError get raised | ||
with suppress(OSError): | ||
sock.setsockopt( | ||
socket.IPPROTO_TCP, socket.TCP_NODELAY, value) | ||
|
||
|
||
def tcp_cork(transport, value): | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.