Permalink
Browse files

Add QCoreApplication event loop to wahjamsrv

Use QCoreApplication::processEvents() instead of sleeping in the main
loop.  This allows us to begin using Qt events in the server and it will
eventually be possible to block while waiting for events instead of
spinning.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
  • Loading branch information...
stefanha committed Apr 10, 2012
1 parent 9da8e4d commit 608bd06ce3c19bbbfbe0857d3dc942c6ee9f151a
Showing with 5 additions and 6 deletions.
  1. +5 −6 ninjam/server/ninjamsrv.cpp
@@ -39,6 +39,8 @@
#include <signal.h>
#include <stdarg.h>
+#include <QCoreApplication>
+
#include "../../WDL/jnetlib/jnetlib.h"
#include "../../WDL/jnetlib/httpget.h"
#include "../netmsg.h"
@@ -646,6 +648,8 @@ bool reloadConfig(int argc, char **argv, bool firstTime)
int main(int argc, char **argv)
{
+ QCoreApplication app(argc, argv);
+
if (argc < 2)
{
usage(argv[0]);
@@ -713,12 +717,7 @@ int main(int argc, char **argv)
{
if (g_server->run())
{
-#ifdef _WIN32
- Sleep(1);
-#else
- struct timespec ts={0,1*1000*1000};
- nanosleep(&ts,NULL);
-#endif
+ app.processEvents(QEventLoop::AllEvents, 1 /* milliseconds */);
if (g_reloadconfig && strcmp(argv[1],"-"))
{

0 comments on commit 608bd06

Please sign in to comment.