Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
572636d4
Unverified
Kaydet (Commit)
572636d4
authored
Ara 16, 2017
tarafından
Yury Selivanov
Kaydeden (comit)
GitHub
Ara 16, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-27456: Ensure TCP_NODELAY is set on linux (#4231) (#4898)
(cherry picked from commit
e796b2fe
)
üst
dab4cf21
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
31 deletions
+53
-31
base_events.py
Lib/asyncio/base_events.py
+22
-21
selector_events.py
Lib/asyncio/selector_events.py
+1
-1
unix_events.py
Lib/asyncio/unix_events.py
+2
-2
test_base_events.py
Lib/test/test_asyncio/test_base_events.py
+0
-7
test_selector_events.py
Lib/test/test_asyncio/test_selector_events.py
+27
-0
2017-11-02-11-57-41.bpo-27456.snzyTC.rst
...S.d/next/Library/2017-11-02-11-57-41.bpo-27456.snzyTC.rst
+1
-0
No files found.
Lib/asyncio/base_events.py
Dosyayı görüntüle @
572636d4
...
...
@@ -84,18 +84,24 @@ def _set_reuseport(sock):
'SO_REUSEPORT defined but not implemented.'
)
def
_is_stream_socket
(
sock
):
# Linux's socket.type is a bitmask that can include extra info
# about socket, therefore we can't do simple
# `sock_type == socket.SOCK_STREAM`.
return
(
sock
.
type
&
socket
.
SOCK_STREAM
)
==
socket
.
SOCK_STREAM
def
_is_stream_socket
(
sock_type
):
if
hasattr
(
socket
,
'SOCK_NONBLOCK'
):
# Linux's socket.type is a bitmask that can include extra info
# about socket (like SOCK_NONBLOCK bit), therefore we can't do simple
# `sock_type == socket.SOCK_STREAM`, see
# https://github.com/torvalds/linux/blob/v4.13/include/linux/net.h#L77
# for more details.
return
(
sock_type
&
0xF
)
==
socket
.
SOCK_STREAM
else
:
return
sock_type
==
socket
.
SOCK_STREAM
def
_is_dgram_socket
(
sock
):
# Linux's socket.type is a bitmask that can include extra info
# about socket, therefore we can't do simple
# `sock_type == socket.SOCK_DGRAM`.
return
(
sock
.
type
&
socket
.
SOCK_DGRAM
)
==
socket
.
SOCK_DGRAM
def
_is_dgram_socket
(
sock_type
):
if
hasattr
(
socket
,
'SOCK_NONBLOCK'
):
# See the comment in `_is_stream_socket`.
return
(
sock_type
&
0xF
)
==
socket
.
SOCK_DGRAM
else
:
return
sock_type
==
socket
.
SOCK_DGRAM
def
_ipaddr_info
(
host
,
port
,
family
,
type
,
proto
):
...
...
@@ -108,14 +114,9 @@ def _ipaddr_info(host, port, family, type, proto):
host
is
None
:
return
None
if
type
==
socket
.
SOCK_STREAM
:
# Linux only:
# getaddrinfo() can raise when socket.type is a bit mask.
# So if socket.type is a bit mask of SOCK_STREAM, and say
# SOCK_NONBLOCK, we simply return None, which will trigger
# a call to getaddrinfo() letting it process this request.
if
_is_stream_socket
(
type
):
proto
=
socket
.
IPPROTO_TCP
elif
type
==
socket
.
SOCK_DGRAM
:
elif
_is_dgram_socket
(
type
)
:
proto
=
socket
.
IPPROTO_UDP
else
:
return
None
...
...
@@ -789,7 +790,7 @@ class BaseEventLoop(events.AbstractEventLoop):
if
sock
is
None
:
raise
ValueError
(
'host and port was not specified and no sock specified'
)
if
not
_is_stream_socket
(
sock
):
if
not
_is_stream_socket
(
sock
.
type
):
# We allow AF_INET, AF_INET6, AF_UNIX as long as they
# are SOCK_STREAM.
# We support passing AF_UNIX sockets even though we have
...
...
@@ -841,7 +842,7 @@ class BaseEventLoop(events.AbstractEventLoop):
allow_broadcast
=
None
,
sock
=
None
):
"""Create datagram connection."""
if
sock
is
not
None
:
if
not
_is_dgram_socket
(
sock
):
if
not
_is_dgram_socket
(
sock
.
type
):
raise
ValueError
(
'A UDP Socket was expected, got {!r}'
.
format
(
sock
))
if
(
local_addr
or
remote_addr
or
...
...
@@ -1054,7 +1055,7 @@ class BaseEventLoop(events.AbstractEventLoop):
else
:
if
sock
is
None
:
raise
ValueError
(
'Neither host/port nor sock were specified'
)
if
not
_is_stream_socket
(
sock
):
if
not
_is_stream_socket
(
sock
.
type
):
raise
ValueError
(
'A Stream Socket was expected, got {!r}'
.
format
(
sock
))
sockets
=
[
sock
]
...
...
@@ -1078,7 +1079,7 @@ class BaseEventLoop(events.AbstractEventLoop):
This method is a coroutine. When completed, the coroutine
returns a (transport, protocol) pair.
"""
if
not
_is_stream_socket
(
sock
):
if
not
_is_stream_socket
(
sock
.
type
):
raise
ValueError
(
'A Stream Socket was expected, got {!r}'
.
format
(
sock
))
...
...
Lib/asyncio/selector_events.py
Dosyayı görüntüle @
572636d4
...
...
@@ -43,7 +43,7 @@ def _test_selector_event(selector, fd, event):
if
hasattr
(
socket
,
'TCP_NODELAY'
):
def
_set_nodelay
(
sock
):
if
(
sock
.
family
in
{
socket
.
AF_INET
,
socket
.
AF_INET6
}
and
sock
.
type
==
socket
.
SOCK_STREAM
and
base_events
.
_is_stream_socket
(
sock
.
type
)
and
sock
.
proto
==
socket
.
IPPROTO_TCP
):
sock
.
setsockopt
(
socket
.
IPPROTO_TCP
,
socket
.
TCP_NODELAY
,
1
)
else
:
...
...
Lib/asyncio/unix_events.py
Dosyayı görüntüle @
572636d4
...
...
@@ -242,7 +242,7 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
if
sock
is
None
:
raise
ValueError
(
'no path and sock were specified'
)
if
(
sock
.
family
!=
socket
.
AF_UNIX
or
not
base_events
.
_is_stream_socket
(
sock
)):
not
base_events
.
_is_stream_socket
(
sock
.
type
)):
raise
ValueError
(
'A UNIX Domain Stream Socket was expected, got {!r}'
.
format
(
sock
))
...
...
@@ -297,7 +297,7 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
'path was not specified, and no sock specified'
)
if
(
sock
.
family
!=
socket
.
AF_UNIX
or
not
base_events
.
_is_stream_socket
(
sock
)):
not
base_events
.
_is_stream_socket
(
sock
.
type
)):
raise
ValueError
(
'A UNIX Domain Stream Socket was expected, got {!r}'
.
format
(
sock
))
...
...
Lib/test/test_asyncio/test_base_events.py
Dosyayı görüntüle @
572636d4
...
...
@@ -116,13 +116,6 @@ class BaseEventTests(test_utils.TestCase):
self
.
assertIsNone
(
base_events
.
_ipaddr_info
(
'::3
%
lo0'
,
1
,
INET6
,
STREAM
,
TCP
))
if
hasattr
(
socket
,
'SOCK_NONBLOCK'
):
self
.
assertEqual
(
None
,
base_events
.
_ipaddr_info
(
'1.2.3.4'
,
1
,
INET
,
STREAM
|
socket
.
SOCK_NONBLOCK
,
TCP
))
def
test_port_parameter_types
(
self
):
# Test obscure kinds of arguments for "port".
INET
=
socket
.
AF_INET
...
...
Lib/test/test_asyncio/test_selector_events.py
Dosyayı görüntüle @
572636d4
...
...
@@ -17,6 +17,7 @@ from asyncio.selector_events import _SelectorTransport
from
asyncio.selector_events
import
_SelectorSslTransport
from
asyncio.selector_events
import
_SelectorSocketTransport
from
asyncio.selector_events
import
_SelectorDatagramTransport
from
asyncio.selector_events
import
_set_nodelay
MOCK_ANY
=
mock
.
ANY
...
...
@@ -1829,5 +1830,31 @@ class SelectorDatagramTransportTests(test_utils.TestCase):
'Fatal error on transport
\n
protocol:.*
\n
transport:.*'
),
exc_info
=
(
ConnectionRefusedError
,
MOCK_ANY
,
MOCK_ANY
))
class
TestSelectorUtils
(
test_utils
.
TestCase
):
def
check_set_nodelay
(
self
,
sock
):
opt
=
sock
.
getsockopt
(
socket
.
IPPROTO_TCP
,
socket
.
TCP_NODELAY
)
self
.
assertFalse
(
opt
)
_set_nodelay
(
sock
)
opt
=
sock
.
getsockopt
(
socket
.
IPPROTO_TCP
,
socket
.
TCP_NODELAY
)
self
.
assertTrue
(
opt
)
@unittest.skipUnless
(
hasattr
(
socket
,
'TCP_NODELAY'
),
'need socket.TCP_NODELAY'
)
def
test_set_nodelay
(
self
):
sock
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
,
proto
=
socket
.
IPPROTO_TCP
)
with
sock
:
self
.
check_set_nodelay
(
sock
)
sock
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_STREAM
,
proto
=
socket
.
IPPROTO_TCP
)
with
sock
:
sock
.
setblocking
(
False
)
self
.
check_set_nodelay
(
sock
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS.d/next/Library/2017-11-02-11-57-41.bpo-27456.snzyTC.rst
0 → 100644
Dosyayı görüntüle @
572636d4
Ensure TCP_NODELAY is set on Linux. Tests by Victor Stinner.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment