[CFSocket] Invalidating a CFSocketRef revisited
[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