Re: POSIX sockets and event loops
Re: POSIX sockets and event loops
- Subject: Re: POSIX sockets and event loops
- From: "Duane Murphy" <email@hidden>
- Date: Thu, 20 May 2004 19:17:52 -0700
--- At Thu, 20 May 2004 20:00:52 -0500, Aaron Ballman wrote:
>
> I would take a look at CFSocket. It's not a large investment and I am
>
> pretty certain that you can isolate the code from the POSIX code. As it
>
> is now it sounds like you're polling select() in order to find out if
>
> there is network I/O.
>
>
So let me see if I have the concept down. I would want to take the BSD
>
socket descriptor I make and pass it into a call to
>
CFSocketCreateWithNative. The options I would want to pass in for the
>
callback type are kCFSocketWriteCallBack and kCFSocketReadCallBack. After
>
creating the CFSocket, I would then make a run loop with
>
CFSocketCreateRunLoopSource and add it with CFRunLoopAddSource.
>
>
Then, in the callback I specify, I can just use my regular socket descriptor
>
to do the reading and the writing?
>
>
Does that sound like an alright scheme?
That's exactly what I do. You _don't_ have to remember your socket
descriptor though. The callback function will give you back the CFSocket,
from which you can retrieve the native socket.
CFSocket is going to want to close the socket when it is closed. I think
there is a way to prevent that from happening as well. I don't know what
it is off hand.
...Duane
_______________________________________________
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.