Example #1
0
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();
}
Example #2
0
// 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();
}
// 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;
}
// 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;
}
Example #5
0
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;
}