527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/** @file
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * IPRT - Async I/O manager.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/*
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Copyright (C) 2013 Oracle Corporation
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * available from http://www.virtualbox.org. This file is free software;
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * you can redistribute it and/or modify it under the terms of the GNU
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * General Public License (GPL) as published by the Free Software
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * The contents of this file may alternatively be used under the terms
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * of the Common Development and Distribution License Version 1.0
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * VirtualBox OSE distribution, in which case the provisions of the
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * CDDL are applicable instead of those of the GPL.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * You may elect to license modified versions of this file under the
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * terms and conditions of either the GPL or the CDDL or both.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync#ifndef ___iprt_aiomgr_h
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync#define ___iprt_aiomgr_h
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync#include <iprt/cdefs.h>
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync#include <iprt/types.h>
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync#include <iprt/sg.h>
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Completion callback.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns nothing.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgrFile File handle the completed request was for.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param rcReq Status code of the completed request.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param pvUser Opaque user data given when the request was initiated.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsynctypedef DECLCALLBACK(void) FNRTAIOMGRREQCOMPLETE(RTAIOMGRFILE hAioMgrFile, int rcReq, void *pvUser);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/** Pointer to a completion callback. */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsynctypedef FNRTAIOMGRREQCOMPLETE *PFNRTAIOMGRREQCOMPLETE;
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRT_C_DECLS_BEGIN
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Create a new async I/O manager.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns IPRT statuse code.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param phAioMgr Where to store the new async I/O manager handle on success.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param cReqsMax Maximum number of async I/O requests expected.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Use UINT32_MAX to make it grow dynamically when required.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(int) RTAioMgrCreate(PRTAIOMGR phAioMgr, uint32_t cReqsMax);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Retain a async I/O manager handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns New reference count on success, UINT32_MAX on failure.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgr The async I/O manager to retain.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(uint32_t) RTAioMgrRetain(RTAIOMGR hAioMgr);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Releases a async I/O manager handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgr The async I/O manager to release.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(uint32_t) RTAioMgrRelease(RTAIOMGR hAioMgr);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Assign a given file handle to the given async I/O manager.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns IPRT status code.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgr Async I/O manager handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hFile File handle to assign.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param pfnReqComplete Callback to execute whenever a request for the
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * file completed.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param phAioMgrFile Where to store the newly created async I/O manager
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * handle on success.
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync * @param pvUser Opaque user data for this file handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @note This function increases the reference count of the given async I/O manager
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * by 1.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(int) RTAioMgrFileCreate(RTAIOMGR hAioMgr, RTFILE hFile, PFNRTAIOMGRREQCOMPLETE pfnReqComplete,
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync void *pvUser, PRTAIOMGRFILE phAioMgrFile);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Retain a async I/O manager file handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns New reference count on success, UINT32_MAX on failure.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgrFile The file handle to retain.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(uint32_t) RTAioMgrFileRetain(RTAIOMGRFILE hAioMgrFile);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Releases a async I/O manager file handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgrFile The file handle to release.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(uint32_t) RTAioMgrFileRelease(RTAIOMGRFILE hAioMgrFile);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync/**
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync * Return opaque user data passed on creation.
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync *
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync * @returns Opaque user data or NULL if the handle is invalid.
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync * @param hAioMgrFile The file handle.
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync */
0840e09d42a5c78e8aea037e99676c212c40a441vboxsyncRTDECL(void *) RTAioMgrFileGetUser(RTAIOMGRFILE hAioMgrFile);
0840e09d42a5c78e8aea037e99676c212c40a441vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Initiate a read request from the given file handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns IPRT status code.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgrFile The file handle to read from.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param off Start offset to read from.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param pSgBuf S/G buffer to read into. The buffer is advanced
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * by the amount of data to read.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param cbRead Number of bytes to read.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param pvUser Opaque user data given in the completion callback.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(int) RTAioMgrFileRead(RTAIOMGRFILE hAioMgrFile, RTFOFF off,
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync PRTSGBUF pSgBuf, size_t cbRead, void *pvUser);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Initiate a write request to the given file handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns IPRT status code.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgrFile The file handle to write to.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param off Start offset to write to.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param pSgBuf S/G buffer to read from. The buffer is advanced
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * by the amount of data to write.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param cbWrite Number of bytes to write.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param pvUser Opaque user data given in the completion callback.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(int) RTAioMgrFileWrite(RTAIOMGRFILE hAioMgrFile, RTFOFF off,
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync PRTSGBUF pSgBuf, size_t cbWrite, void *pvUser);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync/**
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * Initiates a flush request for the given file handle.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync *
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @returns IPRT statuse code.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param hAioMgrFile The file handle to write to.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync * @param pvUser Opaque user data given in the completion callback.
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync */
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRTDECL(int) RTAioMgrFileFlush(RTAIOMGRFILE hAioMgrFile, void *pvUser);
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsyncRT_C_DECLS_END
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync#endif
527eff46676ca64c098dc7d1bf0857408c3a6f82vboxsync