예제 #1
0
    def _receive_data_on_socket(sock, length):
        buf = bytearray(length)
        mv = memoryview(buf)
        bytes_read = 0
        while bytes_read < length:
            try:
                chunk_length = sock.recv_into(mv[bytes_read:])
            except (IOError, OSError) as exc:
                if _errno_from_exception(exc) == errno.EINTR:
                    continue
                raise
            if chunk_length == 0:
                raise AutoReconnect("connection closed")

            bytes_read += chunk_length

        return mv
예제 #2
0
def _receive_data_on_socket(sock_info, length, deadline):
    buf = bytearray(length)
    mv = memoryview(buf)
    bytes_read = 0
    while bytes_read < length:
        try:
            wait_for_read(sock_info, deadline)
            chunk_length = sock_info.sock.recv_into(mv[bytes_read:])
        except (IOError, OSError) as exc:  # noqa: B014
            if _errno_from_exception(exc) == errno.EINTR:
                continue
            raise
        if chunk_length == 0:
            raise OSError("connection closed")

        bytes_read += chunk_length

    return mv
예제 #3
0
    def _receive_data_on_socket(sock, length):
        buf = bytearray(length)
        i = 0
        while length:
            try:
                chunk = sock.recv(length)
            except (IOError, OSError) as exc:
                if _errno_from_exception(exc) == errno.EINTR:
                    continue
                raise
            if chunk == b"":
                raise AutoReconnect("connection closed")

            buf[i:i + len(chunk)] = chunk
            i += len(chunk)
            length -= len(chunk)

        return bytes(buf)
예제 #4
0
 def sendall(self, buf, flags=0):
     view = memoryview(buf)
     total_length = len(buf)
     total_sent = 0
     sent = 0
     while total_sent < total_length:
         try:
             sent = self._call(
                 super(_sslConn, self).send, view[total_sent:], flags)
         # XXX: It's not clear if this can actually happen. PyOpenSSL
         # doesn't appear to have any interrupt handling, nor any interrupt
         # errors for OpenSSL connections.
         except (IOError, OSError) as exc:
             if _errno_from_exception(exc) == _EINTR:
                 continue
             raise
         # https://github.com/pyca/pyopenssl/blob/19.1.0/src/OpenSSL/SSL.py#L1756
         # https://www.openssl.org/docs/man1.0.2/man3/SSL_write.html
         if sent <= 0:
             raise Exception("Connection closed")
         total_sent += sent