Permalink
Browse files

EventLoop: Add finalise().

  • Loading branch information...
1 parent c2ac8b9 commit 9a0a4260f08ff503f6b3e8c4c080afd6c06d0b27 @tindzk committed Jan 28, 2012
Showing with 23 additions and 0 deletions.
  1. +22 −0 src/EventLoop.c
  2. +1 −0 src/EventLoop.h
View
@@ -51,6 +51,17 @@ def(ref(Entry) *, createEntry, void *object, size_t size) {
return entry;
}
+/* Stop listening to input/output. Must be called when the channel's
+ * closure doesn't take effect immediately.
+ */
+def(void, finalise, ref(Entry) *entry) {
+ int flags = ChannelWatcher_Events_Error |
+ ChannelWatcher_Events_HangUp |
+ ChannelWatcher_Events_PeerHangUp;
+
+ ChannelWatcher_Modify(&this->watcher, entry->ch, flags, entry);
+}
+
/* This method can only be called once for each entry. */
def(void, attach, ref(Entry) *entry, ref(Options) opts) {
int flags = ChannelWatcher_Events_Error |
@@ -99,6 +110,17 @@ def(void, detach, ref(Entry) *entry, bool watcher) {
}
static inline def(void, _enqueue, void *entry, int events) {
+ if (BitMask_Has(events,
+ ChannelWatcher_Events_Error |
+ ChannelWatcher_Events_HangUp |
+ ChannelWatcher_Events_PeerHangUp))
+ {
+ /* Hang ups will free resources and must not occur twice
+ * in the event queue.
+ */
+ assert(!EventQueue_hasEvent(&this->queue, entry, events));
+ }
+
EventQueue_Enqueue(&this->queue, entry, events);
}
View
@@ -50,6 +50,7 @@ rsdef(self, New);
def(void, Destroy);
def(void, pullDown, void *object);
def(ref(Entry) *, createEntry, void *object, size_t size);
+def(void, finalise, ref(Entry) *entry);
def(void, attach, ref(Entry) *entry, ref(Options) opts);
def(void, detach, ref(Entry) *entry, bool watcher);
def(void, enqueue, ref(Entry) *entry, int events);

0 comments on commit 9a0a426

Please sign in to comment.