[gnet] [PATCH] Avoid zero watch condition



Hi!

I discovered a strange behaviour with my application that uses gnet:
On certain conditions, its CPU usage would go up to 100% (that
conditions being related to a GConn connection handler not invoking
gnet_conn_write() or gnet_conn_read*()). However, the following patch
(against 2.0.4) fixes the issue, by not making REMOVE_WATCH re-adding
watches with an empty condition (which, as one might argue, should
either cause GLib issue a warning or be a no-op instead of causing its
mainloop to go in CPU-burn-mode).

The three-line patch:

--- gnet-2.0.4.orig/src/conn.c	2003-02-25 21:19:15.000000000 +0100
+++ gnet-2.0.4/src/conn.c	2004-01-12 19:58:45.000000000 +0100
@@ -42,7 +42,9 @@
     (C)->watch_flags &= ~(FLAG);			\
     if ((C)->iochannel) {				\
       if ((C)->watch) g_source_remove ((C)->watch);	\
-      (C)->watch = g_io_add_watch ((C)->iochannel, (C)->watch_flags, async_cb, (C)); \
+      (C)->watch = (C)->watch_flags ? g_io_add_watch ((C)->iochannel, \
+                                                      (C)->watch_flags, \
+                                                      async_cb, (C)) : 0; \
  }}} while (0)
 
 #define UNSET_WATCH (C, FLAG)


Would be nice if that went into 2.0.5.

Thanks, Andy
-- 
Andreas Rottmann         | Rotty ICQ      | 118634484 ICQ | a rottmann gmx at
http://yi.org/rotty      | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62

Latein ist das humanoide Äquivalent zu Fortran.
   -- Alexander Bartolich in at.linux



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]