def _socket_sendfile(self, sfile, offset, nbytes, fallback=False): """ Send data from a file to a remote socket. Returns the number of bytes that were sent to the socket. ========= ==================================================== Argument Description ========= ==================================================== sfile The file to send. offset The number of bytes to offset writing by. nbytes The number of bytes of the file to write. If 0, all bytes will be written. fallback If True, the pure-Python sendfile function will be used. ========= ==================================================== """ try: return sendfile(sfile, self, offset, nbytes, fallback) except Exception as err: if err.args[0] in (errno.EAGAIN, errno.EWOULDBLOCK): self._start_waiting_for_write_event() return err.nbytes # See issue #43 elif err.args[0] == errno.EPIPE: self.close(flush=False) return 0 else: raise
def _socket_sendfile(self, sfile, offset, nbytes): """ ========= ============ Argument Description ========= ============ sfile The file to send. offset The number of bytes to offset writing by. nbytes The number of bytes of the file to write. If 0, all bytes will be written. ========= ============ """ try: return sendfile(sfile, self, offset, nbytes) except Exception, err: if err[0] in (errno.EAGAIN, errno.EWOULDBLOCK): self._wait_for_write_event = True return 0 elif err[0] == errno.EPIPE: self.close() return 0 else: raise