• 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
make stdin a ReadStream?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

make stdin a ReadStream?


  • Subject: make stdin a ReadStream?
  • From: John Chu <email@hidden>
  • Date: Thu, 1 Jan 2004 15:46:20 -0500

Hi,

I'm trying to write program to relay between a socket and stdin/stdout using the Mac OS X specific network interfaces. (I'm fairly certain that I know how to do this using plain vanilla BSD sockets but I'd like to try it with the CF interfaces. I'd also like to take advantage of the SOCKS client code built into CFNetwork. I also realize that this sounds an awful lot like the Echo client that's in the example code. However, the Echo client reads to me like it will block waiting for stdin and I don't want to be stuck blocked on stdin if there happens to be data on the socket. There are also several programs freely available which do something similar. However, I'd like to use the SystemConfiguration framework to discover whether or not I need to use a SOCKS proxy and, if so, its port/host. That bit of it I think I have under control.)

In my current (uncompiled, untested) code, I've opened up the socket using CFStreamCreatePairWithSocketToHost() because this would allow me to set a property to use a SOCKS proxy when opening the connection to the host/port.

From here, I can use CFReadStreamSetClient() to set up a callback from whenever there is something to read from the socket and CFReadStreamScheduleWithRunLoop() to actually put it into the runloop. My callback function would then read from the ReadStream and write it out to stdout. So far so good.

However, how do I do the same thing with stdin? (If I use a callback for the ReadStream, then I need to do the same for stdin, right? Since I've called CFRunLoopRun(), there would be no way to read stdin otherwise.) The alternative is not to use a RunLoop but to wait around until data is available on either source. In vanilla BSD sockets, what I would do is select() on stdin and whatever the fd for the socket is and I would get take care of which ever source happened to have data available first and loop. (I'm ignoring the issue of blocking on the output for now.)

Since I don't know what the underlying fd for the ReadStream is, I can't do that (and besides, I have set up a callback for it). Using select() for just stdin takes me back to the problem I had originally.

I did a search of the archive and found a message from July using CFSocketCreateWithNative() using STDIN_FILENO as the fd (even though STDIN_FILENO is not a socket). This way, as data becomes available on either source, the runtime will call the appropriate callback.

The reply to the message was that it would probably work but it was not what CFSocket was intended for and that it might be easier to use CFStream instead.

I've read through the CFStream documentation many times now, and I haven't found a way of making stdin a ReadStream.

So, is there a way of making stdin a ReadStream? Or is making stdin a CFSocket ok?
Is there some other way of getting a callback when there is data available on stdin?
Or is the right thing to abandon CFStream and go back to BSD sockets? (This would mean doing the negotiation with the SOCKS server myself and I was hoping to avoid that since the OS has facilities to do it for me.) Go multi-threaded? (This sounds like an overkill for what should be a simple program.)

Thanks for any suggestions.

john
email@hidden
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Next by Date: Re: Bringing Up TCP/IP?
  • Next by thread: Re: Bringing Up TCP/IP?
  • Index(es):
    • Date
    • Thread