本文整理汇总了C++中CAsyncRequest类的典型用法代码示例。如果您正苦于以下问题:C++ CAsyncRequest类的具体用法?C++ CAsyncRequest怎么用?C++ CAsyncRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CAsyncRequest类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsAligned
// perform a synchronous read request on this thread.
// may not be aligned - so we will have to buffer.
HRESULT
CAsyncIo::SyncRead(
LONGLONG llPos,
LONG lLength,
BYTE * pBuffer)
{
if(IsAligned(llPos) &&
IsAligned(lLength) &&
IsAligned((LONG_PTR) pBuffer))
{
LONG cbUnused;
return SyncReadAligned(llPos, lLength, pBuffer, &cbUnused, NULL);
}
// not aligned with requirements - use buffered file handle.
//!!! might want to fix this to buffer the data ourselves?
CAsyncRequest request;
HRESULT hr = request.Request(this,
m_pStream,
llPos,
lLength,
FALSE,
pBuffer,
NULL,
0);
if(FAILED(hr))
{
return hr;
}
return request.Complete();
}
示例2: IsAligned
HRESULT
CAsyncIo::SyncRead(
LONGLONG llPos,
LONG lLength,
BYTE* pBuffer)
{
if (IsAligned(llPos) &&
IsAligned(lLength) &&
IsAligned((LONG) pBuffer)) {
LONG cbUnused;
return SyncReadAligned(llPos, lLength, pBuffer, &cbUnused, NULL);
}
CAsyncRequest request;
HRESULT hr = request.Request(
this,
m_pStream,
llPos,
lLength,
FALSE,
pBuffer,
NULL,
0);
if (FAILED(hr)) {
return hr;
}
return request.Complete();
}
示例3: PutWorkItem
// add a request to the queue.
HRESULT
CAsyncIo::Request(
LONGLONG llPos,
LONG lLength,
BOOL bAligned,
BYTE * pBuffer,
LPVOID pContext,
DWORD_PTR dwUser)
{
if(bAligned)
{
if(!IsAligned(llPos) ||
!IsAligned(lLength) ||
!IsAligned((LONG_PTR) pBuffer))
{
return VFW_E_BADALIGN;
}
}
CAsyncRequest* pRequest = new CAsyncRequest;
if (!pRequest)
return E_OUTOFMEMORY;
HRESULT hr = pRequest->Request(this,
m_pStream,
llPos,
lLength,
bAligned,
pBuffer,
pContext,
dwUser);
if(SUCCEEDED(hr))
{
// might fail if flushing
hr = PutWorkItem(pRequest);
}
if(FAILED(hr))
{
delete pRequest;
}
return hr;
}
示例4: lock
// called on thread to process any active requests
void
CAsyncIo::ProcessRequests(void)
{
// lock to get the item and increment the outstanding count
CAsyncRequest * preq = NULL;
for(;;)
{
{
CAutoLock lock(&m_csLists);
preq = GetWorkItem();
if(preq == NULL)
{
// done
return;
}
// one more item not on the done or work list
m_cItemsOut++;
// release critsec
}
preq->Complete();
// regain critsec to replace on done list
{
CAutoLock l(&m_csLists);
PutDoneItem(preq);
if(--m_cItemsOut == 0)
{
if(m_bWaiting)
m_evAllDone.Set();
}
}
}
}
示例5: CheckPointer
// perform a synchronous read request on this thread.
// Need to hold m_csFile while doing this (done in request object)
HRESULT
CAsyncIo::SyncReadAligned(
LONGLONG llPos,
LONG lLength,
BYTE * pBuffer,
LONG * pcbActual,
PVOID pvContext)
{
CheckPointer(pcbActual,E_POINTER);
if(!IsAligned(llPos) ||
!IsAligned(lLength) ||
!IsAligned((LONG_PTR) pBuffer))
{
return VFW_E_BADALIGN;
}
CAsyncRequest request;
m_pStream->Lock();
HRESULT hr = request.Request(this,
m_pStream,
llPos,
lLength,
TRUE,
pBuffer,
pvContext,
0);
if(SUCCEEDED(hr))
{
hr = request.Complete();
}
m_pStream->Unlock();
// return actual data length
*pcbActual = request.GetActualLength();
return hr;
}
示例6: lock
void
CAsyncIo::ProcessRequests(void)
{
CAsyncRequest * preq = NULL;
for (;;) {
{
CAutoLock lock(&m_csLists);
preq = GetWorkItem();
if (preq == NULL) {
return;
}
m_cItemsOut++;
}
preq->Complete();
{
CAutoLock l(&m_csLists);
PutDoneItem(preq);
if (--m_cItemsOut == 0) {
if (m_bWaiting) {
m_evAllDone.Set();
}
}
}
}
}
示例7:
HRESULT
CAsyncIo::SyncReadAligned(
LONGLONG llPos,
LONG lLength,
BYTE* pBuffer,
LONG* pcbActual,
PVOID pvContext
)
{
if (!IsAligned(llPos) ||
!IsAligned(lLength) ||
!IsAligned((LONG) pBuffer)) {
return VFW_E_BADALIGN;
}
CAsyncRequest request;
HRESULT hr = request.Request(
this,
m_pStream,
llPos,
lLength,
TRUE,
pBuffer,
pvContext,
0);
if (FAILED(hr)) {
return hr;
}
hr = request.Complete();
*pcbActual = request.GetActualLength();
return hr;
}
示例8: GetDoneItem
HRESULT
CAsyncIo::WaitForNext(
DWORD dwTimeout,
LPVOID *ppContext,
DWORD * pdwUser,
LONG* pcbActual)
{
*ppContext = NULL;
for (;;) {
if (!m_evDone.Wait(dwTimeout)) {
return VFW_E_TIMEOUT;
}
CAsyncRequest* pRequest = GetDoneItem();
if (pRequest) {
HRESULT hr = pRequest->GetHResult();
if (hr == S_FALSE) {
if ((pRequest->GetActualLength() +
pRequest->GetStart()) == Size()) {
hr = S_OK;
} else {
hr = E_FAIL;
}
}
*pcbActual = pRequest->GetActualLength();
*ppContext = pRequest->GetContext();
*pdwUser = pRequest->GetUser();
delete pRequest;
return hr;
} else {
CAutoLock lck(&m_csLists);
if (m_bFlushing && !m_bWaiting) {
return VFW_E_WRONG_STATE;
}
}
}
}