From: James Antill Date: Sun, 26 Jan 2003 20:39:30 +0000 (+0000) Subject: Don't waste time doin waitqueue manip. for poll() if we have data. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=bc31bcd432b8b8af6d6e87a15a81e07e3ebb6a0b;p=gtetrinet Don't waste time doin waitqueue manip. for poll() if we have data. --- diff --git a/src/gtetrinet.c b/src/gtetrinet.c index eaba04d..8c9f99c 100644 --- a/src/gtetrinet.c +++ b/src/gtetrinet.c @@ -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 ();