]> hydra-www.ietfng.org Git - gtetrinet/commitdiff
Don't waste time doin waitqueue manip. for poll() if we have data.
authorJames Antill <james@src.gnome.org>
Sun, 26 Jan 2003 20:39:30 +0000 (20:39 +0000)
committerJames Antill <james@src.gnome.org>
Sun, 26 Jan 2003 20:39:30 +0000 (20:39 +0000)
src/gtetrinet.c

index eaba04d7c555654f5444945d6532683f1a04f12f..8c9f99c234155367949f2e409839491c2b6b1492 100644 (file)
@@ -1,3 +1,4 @@
+
 /*
  *  GTetrinet
  *  Copyright (C) 1999, 2000, 2001, 2002, 2003  Ka-shu Wong (kswong@zip.com.au)
@@ -75,6 +76,19 @@ static const struct poptOption options[] = {
     {NULL, 0, 0, NULL, 0, NULL, NULL}
 };
 
+static int gtetrinet_poll_func(GPollFD *passed_fds,
+                               guint nfds,
+                               int timeout)
+{ /* passing a timeout wastes time, even if data is ready... don't do that */
+  int ret = 0;
+  struct pollfd *fds = (struct pollfd *)passed_fds;
+
+  ret = poll(fds, nfds, 0);
+  if (!ret && timeout)
+    ret = poll(fds, nfds, timeout);
+
+  return (ret);
+}
 
 int main (int argc, char *argv[])
 {
@@ -252,6 +266,10 @@ int main (int argc, char *argv[])
         client_init (option_connect, nick);
     }
 
+    /* Don't schedule if data is ready, glib should do this itself,
+     * but welcome to anything that works... */
+    g_main_context_set_poll_func(NULL, gtetrinet_poll_func);
+
     /* gtk_main() */
     gtk_main ();