'Forward from src_sock to dest_sock'

def _forward(self, src_sock, dest_sock):

    src_peername = src_sock.getpeername()
    _trace('%s    forwarding    from    %s    to    %s', datetime.utcnow(), src_peername, dest_sock.getpeername())
    try:
        rx_buf = array.array('B', ([0] * self._SOCK_RX_BUF_SIZE))
        while True:
            try:
                nbytes = src_sock.recv_into(rx_buf)
            except socket.error as exc:
                if (exc.errno == errno.EINTR):
                    continue
                elif (exc.errno == errno.ECONNRESET):
                    _trace('%s    errno.ECONNRESET    from    %s', datetime.utcnow(), src_peername)
                    break
                else:
                    _trace('%s    Unexpected    errno=%s    from    %s\n%s', datetime.utcnow(), exc.errno, src_peername, ''.join(traceback.format_stack()))
                    raise
            if (not nbytes):
                _trace('%s    EOF    on    %s', datetime.utcnow(), src_peername)
                break
            try:
                dest_sock.sendall(buffer(rx_buf, 0, nbytes))
            except socket.error as exc:
                if (exc.errno == errno.EPIPE):
                    _trace('%s    Destination    peer    %s    closed    its    end    of    the    connection:    errno.EPIPE', datetime.utcnow(), dest_sock.getpeername())
                    break
                elif (exc.errno == errno.ECONNRESET):
                    _trace('%s    Destination    peer    %s    forcibly    closed    connection:    errno.ECONNRESET', datetime.utcnow(), dest_sock.getpeername())
                    break
                else:
                    _trace('%s    Unexpected    errno=%s    in    sendall    to    %s\n%s', datetime.utcnow(), exc.errno, dest_sock.getpeername(), ''.join(traceback.format_stack()))
                    raise
    except:
        _trace('forward    failed\n%s', ''.join(traceback.format_exc()))
        raise
    finally:
        _trace('%s    done    forwarding    from    %s', datetime.utcnow(), src_peername)
        try:
            _safe_shutdown_socket(src_sock, socket.SHUT_RD)
        finally:
            _safe_shutdown_socket(dest_sock, socket.SHUT_WR)
