Signal handling and Cocoa
Signal handling and Cocoa
- Subject: Signal handling and Cocoa
- From: Juha Pirttilä <email@hidden>
- Date: Tue, 21 May 2002 15:10:53 +0300
Hello!
I have searched high and low, but I have found only a mention
that someone has done sometime this kind of a solution:
1) I have a cross platform daemon that communicates with the GUI
using shared memory. When the shared memory is changed, the
daemon notifies the GUI by sending a SIGUSR1 to the GUI app.
Similarly, when the GUI changes something in the shared mem, it
notifies the daemon by sending a SIGUSR1.
2) Daemon works well on MacOS X, it handles everything OK.
However, if I do the following in my Cocoa incarnation of the
GUI, and send it the SIGUSR1, it stops and complains (in PB)
about receiving a SIGUSR1.
#import <Cocoa/Cocoa.h>
#include <signal.h>
bool sigUsr1Happened = false; // global flag
void sig_DaemonMsg(int signo)
{
// Do something with the acks coming from the daemon
sigUsr1Happened = true;
}
int main(int argc, const char *argv[])
{
signal(SIGUSR1,sig_DaemonMsg); // Register signal handler to
notice the incoming msgs from the daemon
return NSApplicationMain(argc, argv);
}
The signal handler is never called... instead I get a hang. I
get a similar hang if I do not install a signal handler.
I know that in Cocoa we are not supposed to use signals but
instead use more advanced stuff like
NSDistributedNotificationCenters etc, but the daemon is a
cross-platform thingy and it is written in C++. I'd like to keep
the daemon that way for obvious reasons.
So is this approach possible at all? What am I doing wrong? How
should this be done?
Yours,
Juha Pirttila, a newbie Cocoa programmer....
*******************************************************************
* J u h a P i r t t i l
d *
*
*
* email@hidden addr: Invers Ltd *
* tel: work +358-16-619 713 Tdhteldntie
54A *
* mobile +358-40-545 8342
Tdhteld *
* fax +358-16-615 529 FIN-99600
Sodankyld *
*
http://www.invers.fi Finland *
*******************************************************************
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.