listen socket with runloops strange CPU usage
listen socket with runloops strange CPU usage
- Subject: listen socket with runloops strange CPU usage
- From: Nicolas Berloquin <email@hidden>
- Date: Sun, 25 Apr 2004 00:27:35 +0200
Hello !
I just noticed something very strange with a listen socket that I
create by hand (bind/listen),
then transform as a CFSocket with CFSocketCreateWithNative and accept
callback events.
(All inside a cocoa 10.3.x app).
If I add this CFSocketRef as a runLoopSource in the main runloop with:
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSourceRef,
kCFRunLoopDefaultMode);
CPU usage for my app is around 80-90%, and this during the whole time
the app runs.
I had a separate NSThread already running and I noticed that if I add
this CFSocketRef as a runLoopSource
to the second thread's runLoop, CPU usage drops down to 2-4%.
That's a real huge difference. Is this expected behaviour ?
Things you might like to know:
- Same behaviour whether the listen socket is O_NONBLOCK or not.
- I also create (a little later on)
CFSocketCreateConnectedToSocketSignature() as runloopsources on
(either,
but always 100%) the main thread or the second thread (same result).
- I also tried running my accepted connexions on the main or the second
thread (same result).
- I have a G4 bipro.
So my testing on running "everything else" on the second thread or not
makes me think that it's not
foul play or bad secondary effects inside my code, downward from the
socket callback reads etc.
If this is a bug (apple bug ;-)), maybe this workaround should be
advertised ?
_______________________________________________
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.