def send(self, data): """ Send data, and return the number of bytes actually sent. This behaves analogously to the ``send`` system call. Note that ``send`` does not guarantee that all of ``data`` will actually be sent; in most cases, sendall() should be used instead. """ while True: # Try writing the data. try: res = self.remote_sock.send(data) except socket.error, exc: # If we would have blocked, try again later. if exc[0] not in _AGAIN: raise exc else: raise StopIteration(res) yield reactor.wait_for_writeable(self.remote_sock)
# We don't have the sendfile() system call available, so just do the # read and write ourselves. # XXX: This should respect offset, and not suck. data = infile.read(length) yield self.sendall(data) return try: res = sendfile(self.remote_sock.fileno(), infile.fileno(), offset, length) except OSError, exc: if exc.errno in (errno.EPIPE, errno.EBADF): raise ConnectionClosedException() elif exc.errno not in _AGAIN: raise exc yield reactor.wait_for_writeable(self.remote_sock) try: res = sendfile(self.remote_sock.fileno(), infile.fileno(), offset, length) except OSError, exc: if exc.errno in (errno.EPIPE, errno.EBADF): raise ConnectionClosedException() else: raise exc raise StopIteration(res[1]) @coroutine.as_coro def connect(self): """