diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-02-04 22:16:07 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-02-04 22:17:21 +0000 |
commit | 67fa5292823f4c38a35dd83c4948441ce8438d40 (patch) | |
tree | 1f2e678d671a83d8d7e723496155d2ab1bda66fa | |
parent | 92a666f3ff27539655e9130db16bd1587db061de (diff) | |
download | sleepy_penguin-67fa5292823f4c38a35dd83c4948441ce8438d40.tar.gz |
We do not want to share buffers between inotify descriptors.
-rw-r--r-- | ext/sleepy_penguin/inotify.c | 11 | ||||
-rw-r--r-- | test/test_inotify.rb | 13 |
2 files changed, 24 insertions, 0 deletions
diff --git a/ext/sleepy_penguin/inotify.c b/ext/sleepy_penguin/inotify.c index 76082f7..f3a07d9 100644 --- a/ext/sleepy_penguin/inotify.c +++ b/ext/sleepy_penguin/inotify.c @@ -213,6 +213,16 @@ static VALUE events(VALUE self) return rv; } +static VALUE init_copy(VALUE dest, VALUE orig) +{ + VALUE tmp; + + dest = rb_call_super(1, &orig); + rb_ivar_set(dest, id_inotify_buf, rb_str_new(0, 128)); + + return dest; +} + void sleepy_penguin_init_inotify(void) { VALUE mSleepyPenguin, cInotify; @@ -221,6 +231,7 @@ void sleepy_penguin_init_inotify(void) cInotify = rb_define_class_under(mSleepyPenguin, "Inotify", rb_cIO); rb_define_method(cInotify, "add_watch", add_watch, 2); rb_define_method(cInotify, "rm_watch", rm_watch, 1); + rb_define_method(cInotify, "initialize_copy", init_copy, 1); rb_define_method(cInotify, "take", take, -1); cEvent = rb_struct_define(NULL, "wd", "mask", "cookie", "name", NULL); rb_define_const(cInotify, "Event", cEvent); diff --git a/test/test_inotify.rb b/test/test_inotify.rb index f0c135b..ab52b77 100644 --- a/test/test_inotify.rb +++ b/test/test_inotify.rb @@ -12,6 +12,19 @@ class TestInotify < Test::Unit::TestCase assert_kind_of(IO, ino) end + def test_dup + a = Inotify.new + b = a.dup + assert a.fileno != b.fileno + abuf = a.instance_variable_get(:@inotify_buf) + bbuf = b.instance_variable_get(:@inotify_buf) + assert abuf.object_id != bbuf.object_id + + atmp = a.instance_variable_get(:@inotify_tmp) + btmp = b.instance_variable_get(:@inotify_tmp) + assert_equal atmp.object_id, btmp.object_id + end + def test_new_nonblock ino = Inotify.new Inotify::NONBLOCK flags = ino.fcntl(Fcntl::F_GETFL) & Fcntl::O_NONBLOCK |