def sendto (self, *args): """ Send data to the socket. The socket should not be connected to a remote socket, since the destination socket is specified by address. The optional flags argument has the same meaning as for recv() above. Return the number of bytes sent. :param args: :return: """ ## TODO wait_write(self.uv_fd) return self.uv_fd.sendto(*args)
def sendto(self, *args): """ Send data to the socket. The socket should not be connected to a remote socket, since the destination socket is specified by address. The optional flags argument has the same meaning as for recv() above. Return the number of bytes sent. :param args: :return: """ ## TODO wait_write(self.uv_fd) return self.uv_fd.sendto(*args)
def sendfile(out_fd, in_fd, offset, count): total_sent = 0 while total_sent < count: try: _offset, sent = __sendfile.sendfile(out_fd, in_fd, offset + total_sent, count - total_sent) # print '%s: sent %s [%d%%]' % (out_fd, sent, 100*total_sent/count) total_sent += sent except OSError, ex: if ex[0] == EAGAIN: wait_write(out_fd) else: raise
def sendfile(out_fd, in_fd, offset, count): total_sent = 0 while total_sent < count: try: _offset, sent = __sendfile.sendfile(out_fd, in_fd, offset + total_sent, count - total_sent) #print '%s: sent %s [%d%%]' % (out_fd, sent, 100*total_sent/count) total_sent += sent except OSError, ex: if ex[0] == EAGAIN: wait_write(out_fd) else: raise
except pyuv.error.TCPError, e: raise socket.error(*last_socket_error(e.args[0], msg = 'connect error')) else: fd = self.uv_fd if self.gettimeout() is None: while not socket_connect(fd, address): trampoline(fd, write = True) socket_checkerr(fd) else: end = time.time() + self.gettimeout() while True: if socket_connect(fd, address): return if time.time() >= end: raise socket.timeout("timed out") wait_write(fd, end - time.time(), socket.timeout("timed out")) socket_checkerr(fd) def connect_ex (self, address): """ Connects to a remote address not raising exceptions :param address: the remote address, as a IP and port tuple :return: 0 if successful, or an error code otherwise """ if self.act_non_blocking: return self.uv_fd.connect_ex(address) elif self.uv_handle: try: self.connect(address) return 0 except (socket.timeout, Timeout):
raise socket.error( *last_socket_error(e.args[0], msg='connect error')) else: fd = self.uv_fd if self.gettimeout() is None: while not socket_connect(fd, address): trampoline(fd, write=True) socket_checkerr(fd) else: end = time.time() + self.gettimeout() while True: if socket_connect(fd, address): return if time.time() >= end: raise socket.timeout("timed out") wait_write(fd, end - time.time(), socket.timeout("timed out")) socket_checkerr(fd) def connect_ex(self, address): """ Connects to a remote address not raising exceptions :param address: the remote address, as a IP and port tuple :return: 0 if successful, or an error code otherwise """ if self.act_non_blocking: return self.uv_fd.connect_ex(address) elif self.uv_handle: try: self.connect(address) return 0 except (socket.timeout, Timeout):
raise IOError(*e.args) wait_read(self) def sendall (self, data): len_data = len(data) os_write = _os_orig.write fileno = self._fileno try: total_sent = os_write(fileno, data) except OSError, e: if get_errno(e) != errno.EAGAIN: raise IOError(*e.args) total_sent = 0 while total_sent < len_data: wait_write(self) try: total_sent += os_write(fileno, data[total_sent:]) except OSError, e: if get_errno(e) != errno. EAGAIN: raise IOError(*e.args) def __del__ (self): try: _os_orig.close(self._fileno) except: # os.close may fail if __init__ didn't complete (i.e file dscriptor passed to popen was invalid pass def __repr__ (self): return "%s:%d" % (self.__class__.__name__, self._fileno)