Move write_all() to where it's used.

This commit is contained in:
David Wilson 2016-11-01 12:51:27 +00:00
parent 669cc4fdb6
commit 6c8be56c63
2 changed files with 11 additions and 11 deletions

View File

@ -89,16 +89,6 @@ def set_cloexec(fd):
fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC) fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
def write_all(fd, s):
written = 0
while written < len(s):
rc = os.write(fd, buffer(s, written))
if not rc:
raise IOError('short write')
written += rc
return written
class Channel(object): class Channel(object):
def __init__(self, context, handle): def __init__(self, context, handle):
self._context = context self._context = context

View File

@ -70,6 +70,16 @@ def create_child(*args):
return pid, os.dup(parentfp.fileno()) return pid, os.dup(parentfp.fileno())
def write_all(fd, s):
written = 0
while written < len(s):
rc = os.write(fd, buffer(s, written))
if not rc:
raise IOError('short write')
written += rc
return written
def read_with_deadline(fd, size, deadline): def read_with_deadline(fd, size, deadline):
timeout = deadline - time.time() timeout = deadline - time.time()
if timeout > 0: if timeout > 0:
@ -299,7 +309,7 @@ class Stream(econtext.core.Stream):
def _ec0_received(self): def _ec0_received(self):
LOG.debug('%r._ec0_received()', self) LOG.debug('%r._ec0_received()', self)
econtext.core.write_all(self.transmit_side.fd, self.get_preamble()) write_all(self.transmit_side.fd, self.get_preamble())
discard_until(self.receive_side.fd, 'EC1\n', time.time() + 10.0) discard_until(self.receive_side.fd, 'EC1\n', time.time() + 10.0)
def _connect_bootstrap(self): def _connect_bootstrap(self):