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
42279476
Kaydet (Commit)
42279476
authored
Şub 13, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge heads
üst
1392f68e
28773465
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
13 deletions
+59
-13
asyncio-eventloop.rst
Doc/library/asyncio-eventloop.rst
+6
-0
base_events.py
Lib/asyncio/base_events.py
+25
-0
proactor_events.py
Lib/asyncio/proactor_events.py
+8
-1
selector_events.py
Lib/asyncio/selector_events.py
+8
-12
test_events.py
Lib/test/test_asyncio/test_events.py
+12
-0
No files found.
Doc/library/asyncio-eventloop.rst
Dosyayı görüntüle @
42279476
...
...
@@ -366,6 +366,12 @@ Low-level socket operations
Connect to a remote socket at *address*.
The *address* must be already resolved to avoid the trap of hanging the
entire event loop when the address requires doing a DNS lookup. For
example, it must be an IP address, not an hostname, for
:py:data:`~socket.AF_INET` and :py:data:`~socket.AF_INET6` address families.
Use :meth:`getaddrinfo` to resolve the hostname asynchronously.
This method returns a :ref:`coroutine object <coroutine>`.
.. seealso::
...
...
Lib/asyncio/base_events.py
Dosyayı görüntüle @
42279476
...
...
@@ -41,6 +41,31 @@ class _StopError(BaseException):
"""Raised to stop the event loop."""
def
_check_resolved_address
(
sock
,
address
):
# Ensure that the address is already resolved to avoid the trap of hanging
# the entire event loop when the address requires doing a DNS lookup.
family
=
sock
.
family
if
family
not
in
(
socket
.
AF_INET
,
socket
.
AF_INET6
):
return
host
,
port
=
address
type_mask
=
0
if
hasattr
(
socket
,
'SOCK_NONBLOCK'
):
type_mask
|=
socket
.
SOCK_NONBLOCK
if
hasattr
(
socket
,
'SOCK_CLOEXEC'
):
type_mask
|=
socket
.
SOCK_CLOEXEC
# Use getaddrinfo(AI_NUMERICHOST) to ensure that the address is
# already resolved.
try
:
socket
.
getaddrinfo
(
host
,
port
,
family
=
family
,
type
=
(
sock
.
type
&
~
type_mask
),
proto
=
sock
.
proto
,
flags
=
socket
.
AI_NUMERICHOST
)
except
socket
.
gaierror
as
err
:
raise
ValueError
(
"address must be resolved (IP address), got
%
r:
%
s"
%
(
address
,
err
))
def
_raise_stop_error
(
*
args
):
raise
_StopError
...
...
Lib/asyncio/proactor_events.py
Dosyayı görüntüle @
42279476
...
...
@@ -404,7 +404,14 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
return
self
.
_proactor
.
send
(
sock
,
data
)
def
sock_connect
(
self
,
sock
,
address
):
return
self
.
_proactor
.
connect
(
sock
,
address
)
try
:
base_events
.
_check_resolved_address
(
sock
,
address
)
except
ValueError
as
err
:
fut
=
futures
.
Future
(
loop
=
self
)
fut
.
set_exception
(
err
)
return
fut
else
:
return
self
.
_proactor
.
connect
(
sock
,
address
)
def
sock_accept
(
self
,
sock
):
return
self
.
_proactor
.
accept
(
sock
)
...
...
Lib/asyncio/selector_events.py
Dosyayı görüntüle @
42279476
...
...
@@ -208,6 +208,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
return
fut
def
_sock_recv
(
self
,
fut
,
registered
,
sock
,
n
):
# _sock_recv() can add itself as an I/O callback if the operation can't
# be done immediatly. Don't use it directly, call sock_recv().
fd
=
sock
.
fileno
()
if
registered
:
# Remove the callback early. It should be rare that the
...
...
@@ -260,22 +262,16 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
def
sock_connect
(
self
,
sock
,
address
):
"""XXX"""
# That address better not require a lookup! We're not calling
# self.getaddrinfo() for you here. But verifying this is
# complicated; the socket module doesn't have a pattern for
# IPv6 addresses (there are too many forms, apparently).
fut
=
futures
.
Future
(
loop
=
self
)
self
.
_sock_connect
(
fut
,
False
,
sock
,
address
)
try
:
base_events
.
_check_resolved_address
(
sock
,
address
)
except
ValueError
as
err
:
fut
.
set_exception
(
err
)
else
:
self
.
_sock_connect
(
fut
,
False
,
sock
,
address
)
return
fut
def
_sock_connect
(
self
,
fut
,
registered
,
sock
,
address
):
# TODO: Use getaddrinfo() to look up the address, to avoid the
# trap of hanging the entire event loop when the address
# requires doing a DNS lookup. (OTOH, the caller should
# already have done this, so it would be nice if we could
# easily tell whether the address needs looking up or not. I
# know how to do this for IPv4, but IPv6 addresses have many
# syntaxes.)
fd
=
sock
.
fileno
()
if
registered
:
self
.
remove_writer
(
fd
)
...
...
Lib/test/test_asyncio/test_events.py
Dosyayı görüntüle @
42279476
...
...
@@ -1191,6 +1191,18 @@ class EventLoopTestsMixin:
{
'clock_resolution'
:
self
.
loop
.
_clock_resolution
,
'selector'
:
self
.
loop
.
_selector
.
__class__
.
__name__
})
def
test_sock_connect_address
(
self
):
address
=
(
'www.python.org'
,
80
)
for
family
in
(
socket
.
AF_INET
,
socket
.
AF_INET6
):
for
sock_type
in
(
socket
.
SOCK_STREAM
,
socket
.
SOCK_DGRAM
):
sock
=
socket
.
socket
(
family
,
sock_type
)
with
sock
:
connect
=
self
.
loop
.
sock_connect
(
sock
,
address
)
with
self
.
assertRaises
(
ValueError
)
as
cm
:
self
.
loop
.
run_until_complete
(
connect
)
self
.
assertIn
(
'address must be resolved'
,
str
(
cm
.
exception
))
class
SubprocessTestsMixin
:
...
...
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