Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » lack of sigusr1 on windows

This thread is locked; no one can reply to it. rss feed Print
lack of sigusr1 on windows
Mike Farrell
Member #248
April 2000
avatar

Okay so I built this nice little IPC mechanism that works okay on mac. But on windows, I'm stuck without SIGUSR1. So now what the heck can I do? I don't want to use windows' sendmessage api because I'm using GTK for my GUI.

Can I just use SIGTERM or something and catch it in the same regard?

code:
[code]
static void ipc_recv(int i)
{
load(db_path.c_str(), 0, false);
refresh_gl_viewport();
}

void ipc_init()
{
string cdir = config_dir();
db_path = cdir + "/dropbox.xdf";
sig_path = cdir + "/sig";

signal(SIGUSR1, ipc_recv);

ofstream out(sig_path.c_str());
out << getpid() << endl;
out.close();
}

void ipc_send()
{
save(db_path);
if(kill(accu_pid, SIGUSR1) == -1)
perror("");
}
[/code]

GullRaDriel
Member #3,861
September 2003
avatar

If you are using C++, maybe you can do the trick with try/catch
If you are using C, you can emulate that with setjmp and longjmp

Or I misunderstood the question.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Thomas Fjellstrom
Member #476
June 2000
avatar

personally I don't know why you aren't using sockets or pipes.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

GullRaDriel
Member #3,861
September 2003
avatar

AFAIK, Windows = nopipes

I was wrong:
Pipes on Windows

I'd say go with pipes.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Mike Farrell
Member #248
April 2000
avatar

Sockets cause an annoying popup regarding windows defender, the annoying block/unblock dialog. afaik this is right after calling WSAinit.

Pipes block until the both sides open them.

I need a single unidirectional signal to go from one process to the other.

X-G
Member #856
December 2000
avatar

Pipes block until the both sides open them.

No they don't. That's the whole point of the overlapped I/O stuff.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Mike Farrell
Member #248
April 2000
avatar

Wow. this really turned out to be a giant pain in the ass.

Unix solution: less than 10 lines
Windows: not so lucky

This is the only way I could do it without a loop requiring me to continuously poll the status of something whether it be a socket or pipe (I hate doing that).

This is quite ridiculous, but at least I can tuck it away and know that my app will do no processing on behalf of IPC unless the message window gets an event.

#SelectExpand
1#ifdef WIN32 2LRESULT CALLBACK ipc_window_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 3{ 4 switch (message) 5 { 6 case WM_USER: 7 ipc_recv(0); 8 break; 9 default: 10 return DefWindowProc(hWnd, message, wParam, lParam); 11 break; 12 } 13 14 return 0; 15} 16#endif 17 18void ipc_init() 19{ 20 string cdir = config_dir(); 21 db_path = cdir + "/dropbox.xdf"; 22 sig_path = cdir + "/sig"; 23 24#ifndef WIN32 25 signal(SIGUSR1, ipc_recv); 26#else 27 //welcome to hell 28 HINSTANCE inst = (HINSTANCE)GetWindowLong((HWND)GDK_WINDOW_HWND(get_mainwin()->window), GWL_HINSTANCE); 29 WNDCLASSEX wcex; 30 31 wcex.cbSize = sizeof(WNDCLASSEX); 32 wcex.style = 0; 33 wcex.lpfnWndProc = ipc_window_proc; 34 wcex.cbClsExtra = 0; 35 wcex.cbWndExtra = 0; 36 wcex.hCursor = 0; 37 wcex.hbrBackground = 0; 38 wcex.hIcon = 0; 39 wcex.hIconSm = 0; 40 wcex.hInstance = inst; 41 wcex.lpszMenuName = NULL; 42 wcex.lpszClassName = "MyApp Messages"; 43 44 if(!RegisterClassEx(&wcex)) 45 cerr << "Cannot register IPC window class!" << endl; 46 ipc_window = CreateWindow(wcex.lpszClassName, "MyApp IPC", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 47 500, 100, HWND_MESSAGE, NULL, inst/*hInstance*/, NULL); 48 if(!ipc_window) 49 cerr << "Cannot create IPC window (" << (int)GetLastError() << ")" << endl; 50 51#endif 52 53 ofstream out(sig_path.c_str()); 54 out << getpid() << endl; 55 out.close(); 56}

Go to: