Hello. I have two questions about how to use CreateInterfaceAsyncPort. This is a function which is provided by the IOUSBInterfaceInterface class and documented here:
https://developer.apple.com/library/prerelease/mac/documentation/IOKit/Reference/IOUSBInterfaceInterface_reference/ I think my questions also apply to GetInterfaceAsyncPort, CreateDeviceAsyncPort, and GetDeviceAsyncPort. The documentation of CreateInterfaceAsyncPort says: "The OS X kernel does not spawn a thread to callback to the client. Instead it delivers completion notifications on this Mach port. After receiving a message on this port the client is obliged to call the IOKitLib.h IODispatchCalloutFromMessage() function for decoding the notification message." That was the only information I could find on how to use this function; there seem to be no real examples on GitHub. I was able to get it working but I have two questions about the implementation: 1) My understanding is that you need to call mach_msg() to receive data from the returned mach port. That function requires the caller to allocate a buffer to hold the message, and the buffer needs to be big enough to receive the message or else you will get an error. I found that the messages for this particular mach port tend to be roughly 132 bytes, and I made my buffer be 1024 bytes to allow for some margin of error. But I am worried that in a future version of Mac OS X, the message size might increase and break my code. Is there any guarantee on the maximum size of the messages that will be sent on that port? (If not, it seems like the best practice might be to use the MACH_RCV_LARGE option and have a loop for increasing the size of the buffer whenever a message doesn't fit in the buffer.) 2) The third argument to IODispatchCalloutFromMessage() is a void pointer, and it is named "reference". The documentation says to "pass the IONotificationPortRef for the object". There is a notification port, but it is a protected member of IOUSBInterfaceClass, and there is no accessor for it. You can see its definition here: https://github.com/opensource-apple/IOUSBFamily/blob/master/IOUSBLib/Headers/IOUSBInterfaceClass.h Since I was unable to obey the documentation, I simply passed NULL as the third argument and it worked fine. Does the third argument of IODispatchCalloutFromMessage have any effect? Can I see the source code of that function? Is it OK to just pass NULL, as I am already doing? My goal is to be able to submit asynchronous USB transfers and then run a non-blocking function later in order to check their status. I couldn't really see any way of doing that with CreateInterfaceAsyncEventSource, which returns a CFRunLoopSourceRef. I was able to get everything working with CreateInterfaceAsyncPort. Thanks! TL;DR: What is the maximum size of messages on that mach port returned by CreateInterfaceAsyncPort()? Is it OK to supply NULL as the third argument to IODispatchCalloutFromMessage? --David Grayson
_______________________________________________ Do not post admin requests to the list. They will be ignored. Usb mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/usb/archive%40mail-archive.com This email sent to [email protected]
