Re: [Libevent-users] API compatibility (was Re: patch to use different return value for event_base_loop())

2009-10-01 Thread Nick Mathewson
On Tue, Sep 29, 2009 at 11:39:59AM -0700, Ka-Hing Cheung wrote:
> On Sun, 2009-08-16 at 10:39 -0700, Nick Mathewson wrote:
> > > but I am willing to submit another patch (the one with
> > > accessor to base->event_gotterm/event_break) if you think that's the
> > > better way to do it.
> > 
> > Probably.
> 
> Sorry for taking so long. Attached is the promised patch which adds
> accessors to base->event_gotterm/event_break, as well as modifying when
> they are reset in event_base_loop().

Applied; thanks!

-- 
Nick
___
Libevent-users mailing list
Libevent-users@monkey.org
http://lists.monkey.org:8080/listinfo/libevent-users


Re: [Libevent-users] API compatibility (was Re: patch to use different return value for event_base_loop())

2009-09-29 Thread Ka-Hing Cheung
On Sun, 2009-08-16 at 10:39 -0700, Nick Mathewson wrote:
> > but I am willing to submit another patch (the one with
> > accessor to base->event_gotterm/event_break) if you think that's the
> > better way to do it.
> 
> Probably.

Sorry for taking so long. Attached is the promised patch which adds
accessors to base->event_gotterm/event_break, as well as modifying when
they are reset in event_base_loop().

-khc

Index: include/event2/event.h
===
--- include/event2/event.h	(revision 1437)
+++ include/event2/event.h	(working copy)
@@ -300,6 +300,28 @@
  */
 int event_base_loopbreak(struct event_base *);
 
+/**
+  Checks if the event loop was told to exit
+
+  @param eb the event_base structure returned by event_init()
+  @return true if event_base_loopexit() was called on this event base,
+or 0 otherwise
+  @see event_base_loopexit
+  @see event_base_got_break
+ */
+int event_base_got_exit(struct event_base *);
+
+/**
+  Checks if the event loop was told to abort immediately.
+
+  @param eb the event_base structure returned by event_init()
+  @return true if event_base_loopbreak() was called on this event base,
+or 0 otherwise
+  @see event_base_loopbreak
+  @see event_base_got_exit
+ */
+int event_base_got_break(struct event_base *);
+
 /* Flags to pass to event_set(), event_new(), event_assign(),
  * event_pending(), and anything else with an argument of the form
  * "short events" */
Index: event.c
===
--- event.c	(revision 1437)
+++ event.c	(working copy)
@@ -830,8 +830,20 @@
 	}
 }
 
+int
+event_base_got_break(struct event_base *event_base)
+{
+return event_base->event_break;
+}
 
+int
+event_base_got_exit(struct event_base *event_base)
+{
+return event_base->event_gotterm;
+}
 
+
+
 /* not thread safe */
 
 int
@@ -859,15 +871,15 @@
 	base->th_owner_id = EVTHREAD_GET_ID();
 #endif
 
+base->event_gotterm = base->event_break = 0;
+
 	while (!done) {
 		/* Terminate the loop if we have been asked to */
 		if (base->event_gotterm) {
-			base->event_gotterm = 0;
 			break;
 		}
 
 		if (base->event_break) {
-			base->event_break = 0;
 			break;
 		}
 
___
Libevent-users mailing list
Libevent-users@monkey.org
http://lists.monkey.org:8080/listinfo/libevent-users


[Libevent-users] API compatibility (was Re: patch to use different return value for event_base_loop())

2009-08-16 Thread Nick Mathewson
On Thu, Aug 13, 2009 at 11:04:52AM -0700, Ka-Hing Cheung wrote:
> On Thu, 2009-08-13 at 09:16 -0700, Nick Mathewson wrote:
> > On Wed, Aug 12, 2009 at 11:42:47AM -0700, Ka-Hing Cheung wrote:
> >  [...]
> > > I do realize that this breaks existing assumptions about return values.
> > > What if instead of using a different return value, we don't reset
> > > base->event_gotterm and base->event_break when triggered? We can reset
> > > them at the beginning of event_base_loop() instead.
> > 
> > How would you inspect them?  The event_base structure isn't exposed in
> > any public headers.  I suppose we could add a new accessor function.
> 
> Right.
> 
> > I like the idea of the original patch, but I'm also concerned about
> > return values.  If anyone has written code like 
> > "if (event_base_loop(base,0)<0)" or "if (event_base_loop(base,0)==-1)",
> > they'll get unexpected results.
> 
> Yes I like that too. I don't know how strict the api compatibility
> requirement is,

The foremost API requirement is: we don't want to break source
compatibility for existing correct programs.  Breaking existing
programs annoys developers, and prevents distributors from upgrading
to new Libevent versions[*].  Since the return values for
event_base_loop() and friends have been documented and relied upon for
a while, I don't think that we can change them safely.

> but I am willing to submit another patch (the one with
> accessor to base->event_gotterm/event_break) if you think that's the
> better way to do it.

Probably.

yrs,
-- 
Nick

___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users