Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurdarcet committed Nov 8, 2017
1 parent f5366ab commit ed537b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 4 additions & 6 deletions aiohttp/http_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def set_transport(self, transport):
self._transport = transport

if self._buffer is not None:
for b in self._buffer:
transport.write(b)
for chunk in self._buffer:
transport.write(chunk)
self._buffer = None

if self._drain_waiter is not None:
Expand All @@ -163,10 +163,9 @@ def set_transport(self, transport):
async def get_transport(self):
if self._transport is None:
if self._drain_waiter is None:
self._drain_waiter = create_future(self.loop)
self._drain_waiter = self.loop.create_future()
await self._drain_waiter

assert self._transport is not None
return self._transport

@property
Expand Down Expand Up @@ -198,7 +197,6 @@ def _write(self, chunk):

# see set_transport: exactly one of _buffer or _transport is None
if self._transport is not None:
assert self._buffer is None
self._transport.write(chunk)
else:
self._buffer.append(chunk)
Expand Down Expand Up @@ -275,7 +273,7 @@ async def write_eof(self, chunk=b''):
self._transport = None
self._stream.release()

async def drain(self, last=False):
async def drain(self):
if self._transport is not None:
await self._stream.drain()
else:
Expand Down
7 changes: 4 additions & 3 deletions aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
class SendfilePayloadWriter(PayloadWriter):

def __init__(self, *args, **kwargs):
self.__buffer = []
self._sendfile_buffer = []
super().__init__(*args, **kwargs)

def _write(self, chunk):
# we overwrite PayloadWriter._write, so nothing can be appended to
# _buffer, and nothing is written to the transport directly by the
# parent class
self.output_size += len(chunk)
self.__buffer.append(chunk)
self._sendfile_buffer.append(chunk)

def _sendfile_cb(self, fut, out_fd, in_fd,
offset, count, loop, registered):
Expand Down Expand Up @@ -62,8 +62,9 @@ async def sendfile(self, fobj, count):
offset = fobj.tell()

loop = self.loop
data = b''.join(self._sendfile_buffer)
try:
await loop.sock_sendall(out_socket, b''.join(self._buffer))
await loop.sock_sendall(out_socket, data)
fut = loop.create_future()
self._sendfile_cb(fut, out_fd, in_fd, offset, count, loop, False)
await fut
Expand Down

0 comments on commit ed537b7

Please sign in to comment.