• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CFFileDescriptor and stdin
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFFileDescriptor and stdin


  • Subject: Re: CFFileDescriptor and stdin
  • From: Terry Lambert <email@hidden>
  • Date: Sat, 06 Sep 2008 12:28:15 -0700

On Sep 6, 2008, at 9:01 AM, Nicolas Roussel <email@hidden> wrote:
Hi,

I'm trying to use CFFileDescriptors to know when opened files or network sockets are readable.

Although the following code works fine with a file it opens itself, it fails with stdin. It also fails with a dupped version of stdin (tried this thinking the CF machinery might close fd #0 at some point...).

Does anybody know why this doesn't work?

This is something I first ran into with X Window events when using certain widget toolkits (*cough* Motif *cough*) in the late 1980's.


When you wrap a buffered I/O source in a buffeted I/O source, you have to check for data availability in the intermediate buffer before you look to the underlying source. It's possible (and reasonable) for the intermediate source to buffer data in its own buffers, such that there is data available in the intermediate layer buffers without data being available at the underlying data source (i.e. it has already been buffered up).

This leads to having a "do you have data available?" API at each layer that's hard to integrate into a "notify me when data is available" paradigm like "select" or "poll" or "kevent" or "RunLoop", without a wrapper at each layer to peek into layer specific buffer state data. This is going to be a bigger for stdio, since we change it for efficiency reasons all the time.

In general, you should avoid multiple layers of buffering. I would suggest turning buffering off at the stdio layer using setbuf(3).

Alternately, create a subclass that can peek into the stdio buffer and tell if it is empty before looking at the real source and deciding there is no data available (or see that the intermediate buffer is not empty and report "data available" regardless of the state of the primary source; this is what Xselect was invented to do). CF is not cocoa, so it's likely that would end in failure in this case.

My recommenation would be the former (do not use multiple buffering layers).

-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: CFFileDescriptor and stdin
      • From: Nicolas Roussel <email@hidden>
References: 
 >CFFileDescriptor and stdin (From: Nicolas Roussel <email@hidden>)

  • Prev by Date: CFFileDescriptor and stdin
  • Next by Date: Re: CFFileDescriptor and stdin
  • Previous by thread: CFFileDescriptor and stdin
  • Next by thread: Re: CFFileDescriptor and stdin
  • Index(es):
    • Date
    • Thread