Re: CFSocket questions
Re: CFSocket questions
- Subject: Re: CFSocket questions
- From: "Andrew R. Mitchell" <email@hidden>
- Date: Mon, 9 Sep 2002 10:38:39 -0700
The function(whatToDo) which gets executed when data arrives on the
socket....can this also be a method within a class? If so...what would
that look like. The reason I ask this is because I am having a problem
conceptually figuring out how I would actually be able to make more
than one connection via CFSocket if each different socket is going to
reference the same function. So if I had a function which was
responsible for creating and connecting a CFSocket and the function
"whatToDo" which handled the callbacks....how would I differentiate the
data arriving? Meaning if I had 3 sockets connected to 3 different
servers....and all their data is getting handled by function
"whatToDo"...how am I to know what data has just arrived from which
server? Will I need to create an array holding all my sockets so I
know which server, etc?
To expand on the answer Douglas gave a bit (assuming C++ for a
second), yes you can use a method within a class for your callback,
however that method has to be static. What I do is create the
CFSocket within my class and then pass the "this" parameter as my
final argument. The following code snippet shows what I mean and how
I then use "this" within my callback:
class MyObject
{
...
public:
...
static OSStatus MyObjectCallback(CFSocketRef s,
CFSocketCallBackType type,
CFDataRef address, const void *data, void *info);
...
};
OSStatus MyObject::MyObjectCallback(CFSocketRef s, CFSocketCallBackType type,
CFDataRef address, const void *data, void *info)
{
OSStatus err = noErr;
MyObject *This = (MyObject*)info;
// You can now use This-> in place of this->
...
return err;
}
(end of C++ assumption)
Hope this helps.
Andrew
_______________________________________________
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.