• 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: CFSocket questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: CFSocket Callback
  • Next by Date: Re: OS X Socket Performance
  • Previous by thread: Re: CFSocket questions
  • Next by thread: Re: CFSocket questions
  • Index(es):
    • Date
    • Thread