Best way to handle background i/o and notify main UI thread
Best way to handle background i/o and notify main UI thread
- Subject: Best way to handle background i/o and notify main UI thread
- From: Chris Irvine <email@hidden>
- Date: Tue, 1 Jul 2008 15:11:28 -0700
I've been doing a lot of reading about this, but I still don't feel
like I have a concise answer. I'm building a small suite of
applications that all will all share similar interaction with a UDP
based network based peer. It will be necessary to have various
background threaded activities to keep the connection alive and
monitored. I've already built a small proof of concept using a
separate C program that does standard i/o and can be managed by a the
Cocoa front end using NSTask. This is somewhat limiting and isn't
portable to our most favorite mobile device.
It seemed ideal to me to write a class that would provide an opaque
API to handle this communication with an interface very similar to
NSFileHandle and methods like readInBackgroundAndNotify. But the more
I get into it, inter-thread notifications aren't really straight
forward. I've read archived posts about different ways that
NSFileHandle might be implemented. I guess I'm just curious what the
best practice would be for me.
Requirements:
1. Asynchronous i/o using UDP, I'd kinda prefer C-style BSD sockets
for this.
2. Self contained module, easily reused in multiple apps.
3. Lightweight communication of very small payloads to the main thread
where UI can be updated
4. Portable (works on Mac or iPhone)
5. I don't require really require multi-sender or multi-receiver.
Distributed Objects - seems like overkill for my small requirements
NSDistributedNotifcationCenter - discouraged for intra-process
communication
Configure a new main run loop source - I'd have to do a lot more
reading to understand that. Doesn't seem like code that would be
easily reusable.
NSOperation - I only have a single ongoing task. I don't think I need
a queue of 1.
NSThread & performSelectorOnMainThread: - Doesn't seem as opaque and
flexible as NSFileHandle style API with notifications. This is what
I'm leaning toward at the moment.
Something else I'm not thinking of? Suggestions?
-Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden