![]() |
|
lack of sigusr1 on windows |
Mike Farrell
Member #248
April 2000
![]() |
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: void ipc_init() void ipc_send() |
GullRaDriel
Member #3,861
September 2003
![]() |
If you are using C++, maybe you can do the trick with try/catch Or I misunderstood the question. "Code is like shit - it only smells if it is not yours" |
Thomas Fjellstrom
Member #476
June 2000
![]() |
personally I don't know why you aren't using sockets or pipes. -- |
GullRaDriel
Member #3,861
September 2003
![]() |
"Code is like shit - it only smells if it is not yours" |
Mike Farrell
Member #248
April 2000
![]() |
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
![]() |
Mike Farrell said: Pipes block until the both sides open them. No they don't. That's the whole point of the overlapped I/O stuff. -- |
Mike Farrell
Member #248
April 2000
![]() |
Wow. this really turned out to be a giant pain in the ass. Unix solution: less than 10 lines 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. 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}
|
|