You can do something like this -- note, this is not complete, but it does show you how to queue up the multiple reads:
typedef struct
{
UInt32 size;
void * buffer;
} MyRefconData;
MyRefconData gTheData[kNumberOfConcurrentTransfers];
CFRunLoopSourceRef gCFSource;
IOUSBInterfaceInterface245** gInterface;
UInt8 gPipeRef = 0;
//================================================================================================
//
// MyAsyncCallBackFunction
//
// Called when our asynchronous read completes
//
//================================================================================================
//
void
MyAsyncCallBackFunction(void *refCon, IOReturn result, void *arg0)
{
IOReturn kr = kIOReturnSuccess;
MyRefconData * myData = ( MyRefconData *) refCon;
// At this point, we would do something with this data, like looking for a SOF
// Process the Data received
// Re-issue the read
kr = (**gInterface).ReadPipeAsync( gInterface, //
gPipeRef, // pipeRef
myData->buffer, // * buf
myData->size, // size,
MyAsyncCallBackFunction, // Callback
refCon); // Refcon
return;
}
//================================================================================================
//
// ReadFromPipeAsync
//
// Will issue multiple reads to the given pipe
//
//================================================================================================
//
IOReturn ReadFromPipeAsync()
{
IOReturn kr;
// First, we need to create an async event source and add it to our runloop
//
kr = (*gInterface)->CreateInterfaceAsyncEventSource(gInterface,&gCFSource);
require_string(kr == kIOReturnSuccess, Exit, USBErrorToString(kr));
CFRunLoopAddSource(CFRunLoopGetCurrent(), gCFSource, kCFRunLoopDefaultMode);
for ( UInt32 i = 0; i< kNumberOfConcurrentTransfers; i++)
{
// Fill out our refcon
gTheData[i].buffer = XXXXX;
gTheData[i].size = YYYY;
// Queue up the first read
kr = (**gInterface).ReadPipeAsync( gInterface, //
gPipeRef, // pipeRef
gTheData[i].buffer, // * buf
gTheData[i].size, // size,
MyAsyncCallBackFunction, // Callback
(void *)&gTheData[i]); // Refcon
if ( kr != kIOReturnSuccess )
{
printf("ReadIsochPipeAsync returns 0x%x\n",kr);
}
}
Exit:
return kIOReturnSuccess;
}