def METHOD_NAME(sock, bufsize):
    if not sock:
        raise WebSocketConnectionClosedException("socket is already closed.")
    def _recv():
        try:
            return sock.METHOD_NAME(bufsize)
        except SSLWantReadError:
            pass
        except socket.error as exc:
            error_code = extract_error_code(exc)
            if error_code is None:
                raise
            if error_code != errno.EAGAIN or error_code != errno.EWOULDBLOCK:
                raise
        r, w, e = select.select((sock, ), (), (), sock.gettimeout())
        if r:
            return sock.METHOD_NAME(bufsize)
    try:
        if sock.gettimeout() == 0:
            bytes_ = sock.METHOD_NAME(bufsize)
        else:
            bytes_ = _recv()
    except socket.timeout as e:
        message = extract_err_message(e)
        raise WebSocketTimeoutException(message)
    except SSLError as e:
        message = extract_err_message(e)
        if isinstance(message, str) and 'timed out' in message:
            raise WebSocketTimeoutException(message)
        else:
            raise
    if not bytes_:
        raise WebSocketConnectionClosedException(
            "Connection is already closed.")
    return bytes_