NSRunLoop question
NSRunLoop question
- Subject: NSRunLoop question
- From: Mike Laster <email@hidden>
- Date: Wed, 07 Aug 2002 22:07:12 -0400
Am I supposed to be able to run a recursive run loop while within a callout?
I seem to recall doing this in other places and having it work correctly.
I'm trying to integrate a 3rd party networking library into the run loop. I
am able to get access to the raw file handle, so I create a CFSocket with
the native handle, a run loop source and add it. I register for the
kCFSocketReadCallBack callback to get informed when the socket has data
available, but I don't want CoreFoundation to do any reads...I call a
function in the library for this.
My problem is that during my callback, I send a network message and want to
wait for a couple of seconds for a response, but not block the run loop by
polling.
So, I send my message and then do:
NSLog(@">>> run subloop");
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate
dateWithTimeIntervalSinceNow:5.0]];
NSLog(@"<<< run subloop");
This call blocks for the full 5 seconds, even though I know from watching
the other process that a response was sent. As soon as "<<< run subloop" is
printed and the callback is exited, THEN I receive the response. It doesn't
matter if my timout is 5.0 or 30.0. I never get the response within the sub
runloop.
Looking at my runloop, I noticed something odd:
D: (08-07 21:52:24.210) RL = <CFRunLoop 0x144bf0 [0x8016024c]>{locked =
false, wait port = 0x1303, stopped = false,
current mode = kCFRunLoopDefaultMode,
common modes = <CFSet 0x143810 [0x8016024c]>{count = 1, capacity = 3, values
= (
0 : <CFString 0x128c50 [0x8016024c]>{contents =
"kCFRunLoopDefaultMode"}
)},
common mode items = <CFSet 0x144430 [0x8016024c]>{count = 1, capacity = 22,
values = (
3 : <CFRunLoopSource 0x144280 [0x8016024c]>{locked = No, valid =
Yes, order = 1000, context = <CFMachPort 0x1430e0 [0x8016024c]>{locked = No,
valid = Yes, port = 0x1203, source = 0x144280, callout = 0x701932fc, context
= <CFMachPort context 0x0>}}
)},
modes = <CFSet 0x144ea0 [0x8016024c]>{count = 2, capacity = 11, values = (
2 : <CFRunLoopMode 0x142f00 [0x8016024c]>{name = NSConnection
Seeking Reply, locked = false, port set = 0x1503,
sources = <CFSet 0x142f30 [0x8016024c]>{count = 1, capacity = 11,
values = (
3 : <CFRunLoopSource 0x142eb0 [0x8016024c]>{locked = No, valid =
Yes, order = 200, context = <CFMachPort 0x12dfe0 [0x8016024c]>{locked = No,
valid = Yes, port = 0x1103, source = 0x142eb0, callout = 0x708cfd60, context
= <CFMachPort context 0x147400>}}
)},
observers == <CFSet 0x13f870 [0x8016024c]>{count = 1, capacity = 3,
values = (
0 : <CFRunLoopObserver 0x13f830 [0x8016024c]>{locked = Yes, valid =
Yes, activities = 0x2, repeats = Yes, order = 1073741824, callout =
0x708137ac, context = <CFRunLoopObserver context 0x147400>}
)},
timers = (null)
},
4 : <CFRunLoopMode 0x144c40 [0x8016024c]>{name =
kCFRunLoopDefaultMode, locked = false, port set = 0x1403,
sources = <CFSet 0x145110 [0x8016024c]>{count = 3, capacity = 11,
values = (
0 : <CFRunLoopSource 0x14fb90 [0x8016024c]>{locked = No, valid =
Yes, order = 0, context = <CFSocket 0x14fae0 [0x8016024c]>{locked = Yes,
valid = Yes, type = 1, socket = 3, socket set count = 1
callback types = 0x1, callout = 0xa1835, context = <CFSocket context
0x14f870>,
source = 0x14fb90,
run loops = <CFArray 0x14fb40 [0x8016024c]>{type = mutable-small, count
= 1, values = (
0 : <0x144bf0>
)}
}}
3 : <CFRunLoopSource 0x144280 [0x8016024c]>{locked = No, valid =
Yes, order = 1000, context = <CFMachPort 0x1430e0 [0x8016024c]>{locked = No,
valid = Yes, port = 0x1203, source = 0x144280, callout = 0x701932fc, context
= <CFMachPort context 0x0>}}
4 : <CFRunLoopSource 0x142eb0 [0x8016024c]>{locked = No, valid =
Yes, order = 200, context = <CFMachPort 0x12dfe0 [0x8016024c]>{locked = No,
valid = Yes, port = 0x1103, source = 0x142eb0, callout = 0x708cfd60, context
= <CFMachPort context 0x147400>}}
)},
observers == <CFSet 0x13f920 [0x8016024c]>{count = 1, capacity = 3,
values = (
0 : <CFRunLoopObserver 0x13f830 [0x8016024c]>{locked = Yes, valid =
Yes, activities = 0x2, repeats = Yes, order = 1073741824, callout =
0x708137ac, context = <CFRunLoopObserver context 0x147400>}
)},
timers = (null)
},
)}}
My CFSocket is locked. Is the subloop unable to access the socket because
it is behind locked by itself since I'm still in the callout?
If I can't use sub-runloops, how else can I implement "wait n seconds for a
response' behavior?
_______________________________________________
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.