|
31 | 31 | #include <netdb.h> |
32 | 32 | #endif |
33 | 33 |
|
| 34 | +#include <signal.h> |
| 35 | + |
34 | 36 | #include <rfb/rfb.h> |
35 | 37 | #include <rfb/keysym.h> |
36 | 38 |
|
37 | 39 | static const int bpp=4; |
38 | 40 | static int maxx=800, maxy=600; |
39 | 41 | /* TODO: odd maxx doesn't work (vncviewer bug) */ |
40 | 42 |
|
| 43 | +/* Flag used for threaded mode that's global so we can set it via |
| 44 | + a signal handler... */ |
| 45 | +static int maintain_connection = 1; |
| 46 | + |
41 | 47 | /* This initializes a nice (?) background */ |
42 | 48 |
|
43 | 49 | static void initBuffer(unsigned char* buffer) |
@@ -277,6 +283,10 @@ static void MakeRichCursor(rfbScreenInfoPtr rfbScreen) |
277 | 283 | } |
278 | 284 | } |
279 | 285 |
|
| 286 | +void intHandler(int dummy) { |
| 287 | + maintain_connection = 0; |
| 288 | +} |
| 289 | + |
280 | 290 | /* Initialization */ |
281 | 291 |
|
282 | 292 | int main(int argc,char** argv) |
@@ -324,12 +334,17 @@ int main(int argc,char** argv) |
324 | 334 | #if !defined(LIBVNCSERVER_HAVE_LIBPTHREAD) && !defined(LIBVNCSERVER_HAVE_WIN32THREADS) |
325 | 335 | #error "I need pthreads or win32 threads for that." |
326 | 336 | #endif |
327 | | - |
| 337 | + /* catch Ctrl-C to set a flag for the main thread */ |
| 338 | + signal(SIGINT, intHandler); |
328 | 339 | /* this is the non-blocking event loop; a background thread is started */ |
329 | 340 | rfbRunEventLoop(rfbScreen,-1,TRUE); |
330 | 341 | fprintf(stderr, "Running background loop...\n"); |
331 | 342 | /* now we could do some cool things like rendering in idle time */ |
332 | | - while(1) sleep(5); /* render(); */ |
| 343 | + while (maintain_connection) { |
| 344 | + sleep(5); /* render(); */ |
| 345 | + } |
| 346 | + fprintf(stderr, "\nShutting down...\n"); |
| 347 | + rfbShutdownServer(rfbScreen, TRUE); |
333 | 348 | #endif /* BACKGROUND_LOOP */ |
334 | 349 |
|
335 | 350 | free(rfbScreen->frameBuffer); |
|
0 commit comments