K880
K880

Reputation: 31

How to create IOUSBHostPipe::CompleteAsyncIO callback

I'm creating a driver to communicate with a USB device. I try to make an asynchronous bulk data read by using AsyncIO. The problem I'm facing is that my CompleteAsyncIO doesn't get called when the AsyncIO's completionTimeoutMs parameter is set to 0. When I change this AsyncIO timeout to a non zero value such as 500 ms, I notice CompleteAsyncIO gets called but I keep getting kIOReturnTimeout error. Increasing the timeout doesn't help.

struct MyDriver_IVars {
    OSAction* callbackAction = nullptr;     // registered callback action by app
    IOUSBHostInterface* interface;
    IOUSBHostPipe* pipe;
    IOBufferMemoryDescriptor* inDataBuffer;
    OSAction* ioCompleteCallback = nullptr; // read complete callback action
    uint32_t MAX_LENGTH = 1024;
};

kern_return_t IMPL(MyDriver, Start){
.................
ret = ivars->interface->CopyPipe(endpoint->bEndpointAddress, &ivars->pipe);
ret = ivars->interface->CreateIOBuffer(kIOMemoryDirectionInOut, ivars->MAX_LENGTH, &ivars->inDataBuffer);
ret = CreateActionReadComplete(ivars->MAX_LENGTH, &ivars->ioCompleteCallback);
.................
}

kern_return_t MyDriver::ReadData(int nbytes, int timeout)
{
.................
    kern_return_t ret = ivars->pipe->AsyncIO(ivars->inDataBuffer, ivars->MAX_LENGTH, ivars->ioCompleteCallback, 0);
.................
}


void IMPL(MyDriver, ReadComplete)
{
Log("ReadComplete() - status - %d; bytes count - %d", status, actualByteCount);

    //AsyncCompletion(ivars->callbackAction, ..................

}

In my application, I set up a loop that makes IOConnectCallAsyncStructMethod calls, which ends up calling MyDriver::ReadData to enqueue the requests. I'm hoping to get a successful ReadComplete so that I can get the data back but I keep getting the timeout, or a no-call.

Any idea what I'm doing wrong?

Thank you

Upvotes: 1

Views: 90

Answers (0)

Related Questions