sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [sleepy.penguin] [PATCH 0/17] kqueue and epoll fixes
@ 2013-04-30  2:39  6% Eric Wong
  2013-04-30  2:39  7% ` [sleepy.penguin] [PATCH 13/17] kqueue: workaround lack of RSTRUCT* macros on Rubinius Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2013-04-30  2:39 UTC (permalink / raw)
  To: sleepy.penguin

I'm slowly fleshing out kqueue support and also fixing some
timing-related bugs in the test suite.  kqueue support is
tested on FreeBSD 9.1

The kqueue code should also be compatible with Rubinius,
(tested against the stable libkqueue branch under Linux)

(diffstat against "master")

 ext/sleepy_penguin/epoll.c          |  15 +-
 ext/sleepy_penguin/extconf.rb       |   6 +-
 ext/sleepy_penguin/init.c           |  11 +
 ext/sleepy_penguin/kqueue.c         | 643 ++++++++++++++++++++++++++++++++++++
 ext/sleepy_penguin/sleepy_penguin.h |  12 +
 ext/sleepy_penguin/value2timespec.h |   2 +-
 lib/sleepy_penguin.rb               |   1 -
 lib/sleepy_penguin/epoll.rb         |  53 +--
 lib/sleepy_penguin/kevent.rb        |   3 +
 lib/sleepy_penguin/kqueue.rb        | 115 +++++++
 lib/sleepy_penguin/kqueue/io.rb     |  30 ++
 pkg.mk                              |   2 +-
 test/test_epoll.rb                  |  89 +++--
 test/test_epoll_io.rb               |   3 +-
 test/test_epoll_optimizations.rb    |   1 -
 test/test_inotify.rb                |   2 +-
 test/test_kqueue.rb                 |  75 +++++
 test/test_kqueue_io.rb              | 107 ++++++
 test/test_timerfd.rb                |   4 +-
 19 files changed, 1078 insertions(+), 96 deletions(-)

Eric Wong (17):
      test_epoll: remove assert_nothing_raised
      test: remove Rubinius-specific checks and skips
      test_epoll: avoid sleeping inside a signal handler
      fork-safe "to_io" in high-level epoll/kqueue
      test_kqueue: join thread after test
      test_kqueue_io: test for multiple event return
      test_timerfd: relax timing-sensitive test
      kqueue: set zero timeout if not retrieving events
      test_epoll: workaround MRI 1.8 threading bug
      test_kqueue_io: join thread in test when done using
      test_kqueue: only test if IO#autoclose= exists
      kqueue/io: fix MRI 1.8 support code for event retrieval
      kqueue: workaround lack of RSTRUCT* macros on Rubinius
      test_epoll: join thread before return from test
      test_epoll: increase delay between signal spamming
      epoll: clear FD marks snapshot before returning
      test_epoll: workaround race condition in test_close


^ permalink raw reply	[relevance 6%]

* [sleepy.penguin] [PATCH 13/17] kqueue: workaround lack of RSTRUCT* macros on Rubinius
  2013-04-30  2:39  6% [sleepy.penguin] [PATCH 0/17] kqueue and epoll fixes Eric Wong
@ 2013-04-30  2:39  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2013-04-30  2:39 UTC (permalink / raw)
  To: sleepy.penguin

Rubinius will not support RSTRUCT* macros, so converting the
structs to arrays is the least intrusive way to go about our
code.

ref: https://github.com/rubinius/rubinius/issues/494
---
 ext/sleepy_penguin/kqueue.c | 70 ++++++++++++++++++++++++++++++++-------------
 test/test_kqueue_io.rb      |  6 ++++
 2 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/ext/sleepy_penguin/kqueue.c b/ext/sleepy_penguin/kqueue.c
index 78a13c3..155204b 100644
--- a/ext/sleepy_penguin/kqueue.c
+++ b/ext/sleepy_penguin/kqueue.c
@@ -24,6 +24,18 @@
 #  define NUM2USHORT(n) (short)NUM2UINT(n)
 #endif
 
+/*
+ * Rubinius does not support RSTRUCT_* in the C API:
+ * ref: https://github.com/rubinius/rubinius/issues/494
+ */
+#if defined(RUBINIUS)
+#  define RBX_STRUCT (1)
+#  define RSTRUCT_LEN(s) 0, rb_bug("RSTRUCT_LEN attempted in Rubinius")
+#  define RSTRUCT_PTR(s) NULL, rb_bug("RSTRUCT_PTR attempted in Rubinius")
+#else
+#  define RBX_STRUCT (0)
+#endif
+
 static const long NANO_PER_SEC = 1000000000;
 static ID id_for_fd;
 static VALUE mEv, mEvFilt, mNote, mVQ;
@@ -233,33 +245,42 @@ static void event_set(struct kevent *event, VALUE *chg)
 	EV_SET(event, ident, filter, flags, fflags, data, udata);
 }
 
+/* sets ptr and len */
+static void unpack_event(VALUE **ptr, VALUE *len, VALUE *event)
+{
+	switch (TYPE(*event)) {
+	case T_STRUCT:
+		if (RBX_STRUCT) {
+			*event = rb_funcall(*event, rb_intern("to_a"), 0, 0);
+			/* fall-through to T_ARRAY */
+		} else {
+			*len = RSTRUCT_LEN(*event);
+			*ptr = RSTRUCT_PTR(*event);
+			return;
+		}
+	case T_ARRAY:
+		*len = RARRAY_LEN(*event);
+		*ptr = RARRAY_PTR(*event);
+		return;
+	default:
+		rb_raise(rb_eTypeError, "unsupported type in changelist");
+	}
+}
+
 static void ary2eventlist(struct kevent *events, VALUE changelist)
 {
 	VALUE *chg = RARRAY_PTR(changelist);
 	long i = RARRAY_LEN(changelist);
+	VALUE event;
 
 	for (; --i >= 0; chg++) {
 		VALUE clen;
 		VALUE *cptr;
 
-		switch (TYPE(*chg)) {
-		case T_STRUCT:
-			clen = RSTRUCT_LEN(*chg);
-			cptr = RSTRUCT_PTR(*chg);
-			break;
-		case T_ARRAY:
-			clen = RARRAY_LEN(*chg);
-			cptr = RARRAY_PTR(*chg);
-			break;
-		default:
-			rb_raise(rb_eTypeError,
-				 "unsupported type in changelist");
-		}
-		if (clen != 6) {
-			fprintf(stderr, "clen: %ld\n", clen);
-			rb_p(*chg);
+		event = *chg;
+		unpack_event(&cptr, &clen, &event);
+		if (clen != 6)
 			goto out_list;
-		}
 		event_set(events++, cptr);
 	}
 	return;
@@ -273,14 +294,23 @@ out_list:
  */
 static void changelist_prepare(struct kevent *events, VALUE changelist)
 {
+	VALUE *cptr;
+	VALUE clen;
+	VALUE event;
+
 	switch (TYPE(changelist)) {
 	case T_ARRAY:
 		ary2eventlist(events, changelist);
-		break;
+		return;
 	case T_STRUCT:
-		if (RSTRUCT_LEN(changelist) != 6)
+		event = changelist;
+		unpack_event(&cptr, &clen, &event);
+		if (clen != 6)
 			rb_raise(rb_eTypeError, "event is not a Kevent struct");
-		event_set(events, RSTRUCT_PTR(changelist));
+		event_set(events, cptr);
+		return;
+	default:
+		rb_bug("changelist_prepare not type filtered by sp_kevent");
 	}
 }
 
diff --git a/test/test_kqueue_io.rb b/test/test_kqueue_io.rb
index 904a1cc..076c9f0 100644
--- a/test/test_kqueue_io.rb
+++ b/test/test_kqueue_io.rb
@@ -16,6 +16,12 @@ def teardown
     end
   end
 
+  def test_bad_type
+    kq = Kqueue::IO.new
+    @to_close << kq
+    assert_raises(TypeError) { kq.kevent("HI") }
+  end
+
   def test_multi_event
     kq = Kqueue::IO.new
     @to_close << kq
-- 
1.8.2.1.367.gc875ca7



^ permalink raw reply related	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2013-04-30  2:39  6% [sleepy.penguin] [PATCH 0/17] kqueue and epoll fixes Eric Wong
2013-04-30  2:39  7% ` [sleepy.penguin] [PATCH 13/17] kqueue: workaround lack of RSTRUCT* macros on Rubinius Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/sleepy_penguin.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).