How to get backchannel file descriptor

Michael Sweet mike at easysw.com
Wed Aug 20 09:47:43 PDT 2008


keens312 wrote:
>> keens312 wrote:
>>>> keens312 wrote:
>>>>> Hi Michael,
>>>>>
>>>>> In the filter for backchannel, I created a thread to keep reading feedback from printer...
>>>>>
>>>>> On OSX 10.5, CUPS has created backchannel FDs for USB and Network backends.
>>>>>
>>>>> The question is how to get the correct file descriptor in filter?
>>>> Use the supplied API: cupsBackChannelRead.  The file descriptor itself
>>>> is #3.
>>>>
>>>> --
>>>> ______________________________________________________________________
>>>> Michael R Sweet                        Senior Printing System Engineer
>>>>
>>> To support OSX 10.3.9, I don't use cupsBackChannelRead.
>>>
>>> I am going to use fixed FD #3 for backchannel, hoping this FD will never be changed.
>> We have no plans to change it, but you shouldn't depend on that.
>>
>> Use weak linking and test for the availability of the function at
>> run-time:
>>
>>      if (cupsBackChannelRead != NULL)
>>        /* start read thread */
>>
>> --
>> ______________________________________________________________________
>> Michael R Sweet                        Senior Printing System Engineer
>>
> Hi Michael,
> 
> I created a thread for reading from backchannel in filter.
> In the thread, there is a loop, keep pooling data from bc.
> Async way to read data, is there some code I can reference in CUPS?
> my impl might have bugs that missing some feedback data from bc.

There is no async IO API in CUPS; if you pass 0 for the timeout
parameter of cupsBackChannelRead, it will do a poll.  -1 waits
indefinitely, and > 0 waits for that number of seconds.

If you have a separate read thread, just loop on cupsBackChannelRead
with a timeout of -1.

That said, if your device returns a lot of data (more than, say,
4k per second) you may lose data since the back channel is a non-
blocking pipe between the backend and filter to prevent deadlocks.

-- 
______________________________________________________________________
Michael Sweet, Easy Software Products           mike at easysw dot com




More information about the cups-devel mailing list