Hi,

2014-08-25 11:52 GMT+02:00 Martin Richard <[email protected]>:
> The method loop.create_server() allows to use an existing socket, but will
> however perform a call to listen() on that socket. I am not sure why it's
> not up the user creating the socket to perform that call. In particular, on
> Linux (I don't know for others systems), it will change the backlog size to
> the value of the latest call to listen. It might happen that the user does
> not know the size of the backlog and does not want to change it - for
> instance when the socket is created with socket.fromfd(). Maybe it's enough
> if this behavior is documented, since there is a simple workaround (subclass
> socket.socket and make listen() a no-op).

It's probably a bug.


> I also have questions about StreamWriter and the flow control system.
>
> I understood that I am expected to yield from writer.drain() after any call
> to writer.write(), so the flow control mechanism can make the calling task
> wait until the buffer gets downsized to the low-water limit.

Nope, see the documentation:

"drain():
Wait until the write buffer of the underlying transport is flushed."

> I don't
> understand why the writer.write[lines]() functions are not coroutines which
> actually yield from writer.drain(), nor why the "yield from writer.drain()"
> is not performed before the call to write().

The purpose of a buffer is performances. You may be able to pack
multiple small writes into a single call to socket.send(). Flushing
after each call to stream.write() would call socket.send() each time,
which is less efficient.

In fact, you don't need to wait for drain(), asyncio automatically
flushs the buffer "in background". drain() is only required when you
have to respect a protocol, for example write and then read when the
write is done.

> On a related topic, is there a reason why StreamWriter does not have a
> flush() coroutine, or any other way to wait until the buffer is empty? The
> only workaround I've got for this is to temporarily force high and low water
> limits to 0 so writer.drain() will wait until the buffer is actually empty.

Limits are only used to pause the protocol. The protocol is not
directly related to the buffer.

Victor

Reply via email to