• 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
[CFSocket] Invalidating a CFSocketRef revisited
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[CFSocket] Invalidating a CFSocketRef revisited


  • Subject: [CFSocket] Invalidating a CFSocketRef revisited
  • From: Stéphane Sudre <email@hidden>
  • Date: Thu, 20 Jan 2011 18:26:54 +0100

Just wanted to share a "funny" case I faced related to CFSocketRef invalidation and why it can sometimes be useful to invalidate a socket for a kCFSocketDataCallBack call with empty data.


When receiving empty data via a kCFSocketDataCallBack, I was relying on the fact that the CFSocketRef instance would be invalidated automatically.


Unfortunately, there can be some kind of reentrancy issues with kCFSocketDataCallBack.

For instance, if you send a message port from your callback and wait for an answer, a run loop is created. While the process is waiting for the message port answer, the socket call back is called a second time with empty data again.

This gives something like this:


MyProcessSocketCallBack

  callback type is kCFSocketDataCallBack

    data is empty

      send message port and wait for answer

          MyProcessSocketCallBack

             callback type is kCFSocketDataCallBack

    		data is empty


Invalidating the socket from MyProcessSocketCallBack fixes the issue.

Disabling the callbacks for the CFSocketRef instead of invalidating the CFSocketRef does not fix it. I haven't checked in the CFSocket.c file the reason for this.





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


  • Follow-Ups:
    • Re: [CFSocket] Invalidating a CFSocketRef revisited
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
  • Prev by Date: Best practice for large packets
  • Next by Date: Re: [CFSocket] Invalidating a CFSocketRef revisited
  • Previous by thread: Best practice for large packets
  • Next by thread: Re: [CFSocket] Invalidating a CFSocketRef revisited
  • Index(es):
    • Date
    • Thread