Commit d143209d authored by Victor Stinner's avatar Victor Stinner

Tulip issue 83: document more asyncio functions in docstrings

parent 54c4b8e5
...@@ -311,11 +311,10 @@ Creating listening connections ...@@ -311,11 +311,10 @@ Creating listening connections
.. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None) .. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, \*, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None)
A :ref:`coroutine <coroutine>` method which creates a TCP server bound to Create a TCP server bound to host and port. Return an
host and port. :class:`AbstractServer` object which can be used to stop the service.
The return value is a :class:`AbstractServer` object which can be used to stop This method is a :ref:`coroutine <coroutine>`.
the service.
If *host* is an empty string or None all interfaces are assumed If *host* is an empty string or None all interfaces are assumed
and a list of multiple sockets will be returned (most likely and a list of multiple sockets will be returned (most likely
......
...@@ -320,7 +320,7 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -320,7 +320,7 @@ class BaseEventLoop(events.AbstractEventLoop):
"than the current one") "than the current one")
def call_soon_threadsafe(self, callback, *args): def call_soon_threadsafe(self, callback, *args):
"""XXX""" """Like call_soon(), but thread safe."""
handle = self._call_soon(callback, args, check_loop=False) handle = self._call_soon(callback, args, check_loop=False)
self._write_to_self() self._write_to_self()
return handle return handle
...@@ -358,7 +358,17 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -358,7 +358,17 @@ class BaseEventLoop(events.AbstractEventLoop):
def create_connection(self, protocol_factory, host=None, port=None, *, def create_connection(self, protocol_factory, host=None, port=None, *,
ssl=None, family=0, proto=0, flags=0, sock=None, ssl=None, family=0, proto=0, flags=0, sock=None,
local_addr=None, server_hostname=None): local_addr=None, server_hostname=None):
"""XXX""" """Connect to a TCP server.
Create a streaming transport connection to a given Internet host and
port: socket family AF_INET or socket.AF_INET6 depending on host (or
family if specified), socket type SOCK_STREAM. protocol_factory must be
a callable returning a protocol instance.
This method is a coroutine which will try to establish the connection
in the background. When successful, the coroutine returns a
(transport, protocol) pair.
"""
if server_hostname is not None and not ssl: if server_hostname is not None and not ssl:
raise ValueError('server_hostname is only meaningful with ssl') raise ValueError('server_hostname is only meaningful with ssl')
...@@ -557,7 +567,12 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -557,7 +567,12 @@ class BaseEventLoop(events.AbstractEventLoop):
backlog=100, backlog=100,
ssl=None, ssl=None,
reuse_address=None): reuse_address=None):
"""XXX""" """Create a TCP server bound to host and port.
Return an AbstractServer object which can be used to stop the service.
This method is a coroutine.
"""
if isinstance(ssl, bool): if isinstance(ssl, bool):
raise TypeError('ssl argument must be an SSLContext or None') raise TypeError('ssl argument must be an SSLContext or None')
if host is not None or port is not None: if host is not None or port is not None:
......
...@@ -226,7 +226,14 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): ...@@ -226,7 +226,14 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
return False return False
def sock_recv(self, sock, n): def sock_recv(self, sock, n):
"""XXX""" """Receive data from the socket.
The return value is a bytes object representing the data received.
The maximum amount of data to be received at once is specified by
nbytes.
This method is a coroutine.
"""
fut = futures.Future(loop=self) fut = futures.Future(loop=self)
self._sock_recv(fut, False, sock, n) self._sock_recv(fut, False, sock, n)
return fut return fut
...@@ -253,7 +260,16 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): ...@@ -253,7 +260,16 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
fut.set_result(data) fut.set_result(data)
def sock_sendall(self, sock, data): def sock_sendall(self, sock, data):
"""XXX""" """Send data to the socket.
The socket must be connected to a remote socket. This method continues
to send data from data until either all data has been sent or an
error occurs. None is returned on success. On error, an exception is
raised, and there is no way to determine how much data, if any, was
successfully processed by the receiving end of the connection.
This method is a coroutine.
"""
fut = futures.Future(loop=self) fut = futures.Future(loop=self)
if data: if data:
self._sock_sendall(fut, False, sock, data) self._sock_sendall(fut, False, sock, data)
...@@ -285,7 +301,16 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): ...@@ -285,7 +301,16 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
self.add_writer(fd, self._sock_sendall, fut, True, sock, data) self.add_writer(fd, self._sock_sendall, fut, True, sock, data)
def sock_connect(self, sock, address): def sock_connect(self, sock, address):
"""XXX""" """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 AF_INET and
AF_INET6 address families. Use getaddrinfo() to resolve the hostname
asynchronously.
This method is a coroutine.
"""
fut = futures.Future(loop=self) fut = futures.Future(loop=self)
try: try:
base_events._check_resolved_address(sock, address) base_events._check_resolved_address(sock, address)
...@@ -318,7 +343,15 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): ...@@ -318,7 +343,15 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
fut.set_result(None) fut.set_result(None)
def sock_accept(self, sock): def sock_accept(self, sock):
"""XXX""" """Accept a connection.
The socket must be bound to an address and listening for connections.
The return value is a pair (conn, address) where conn is a new socket
object usable to send and receive data on the connection, and address
is the address bound to the socket on the other end of the connection.
This method is a coroutine.
"""
fut = futures.Future(loop=self) fut = futures.Future(loop=self)
self._sock_accept(fut, False, sock) self._sock_accept(fut, False, sock)
return fut return fut
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment