From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS6939 64.71.128.0/18 X-Spam-Status: No, score=-2.0 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.kgio.general Subject: [PATCH 2/3] autopush: fix/enable under Debian GNU/kFreeBSD Date: Mon, 5 Mar 2012 23:47:09 +0000 Message-ID: <1330991229-21167-1-git-send-email-normalperson@yhbt.net> References: <20120305234508.GA15184@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1330991261 8218 80.91.229.3 (5 Mar 2012 23:47:41 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 5 Mar 2012 23:47:41 +0000 (UTC) To: kgio@librelist.org Original-X-From: kgio@librelist.org Tue Mar 06 00:47:41 2012 Return-path: Envelope-to: gclrkg-kgio@m.gmane.org List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: kgio@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.kgio.general:95 Archived-At: Received: from zedshaw.xen.prgmr.com ([64.71.167.205]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S4hcu-0007ul-95 for gclrkg-kgio@m.gmane.org; Tue, 06 Mar 2012 00:47:36 +0100 Received: from zedshaw.xen.prgmr.com (localhost [IPv6:::1]) by zedshaw.xen.prgmr.com (Postfix) with ESMTP id EA35621D441 for ; Mon, 5 Mar 2012 23:53:27 +0000 (UTC) It seems autopush support in our autopush code has always been broken outside of Linux-based systems, as we never marked the socket as having pending data. --- ext/kgio/autopush.c | 1 + ext/kgio/read_write.c | 13 +++++++++++++ test/test_autopush.rb | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/kgio/autopush.c b/ext/kgio/autopush.c index 7c5553f..74576e8 100644 --- a/ext/kgio/autopush.c +++ b/ext/kgio/autopush.c @@ -240,6 +240,7 @@ static void push_pending_data(VALUE io) } #else /* !KGIO_NOPUSH */ void kgio_autopush_recv(VALUE io){} +void kgio_autopush_send(VALUE io){} void init_kgio_autopush(void) { } diff --git a/ext/kgio/read_write.c b/ext/kgio/read_write.c index 6f739a5..9c2440e 100644 --- a/ext/kgio/read_write.c +++ b/ext/kgio/read_write.c @@ -13,8 +13,18 @@ static ID id_set_backtrace; #if defined(__linux__) && ! defined(USE_MSG_DONTWAIT) # define USE_MSG_DONTWAIT static const int peek_flags = MSG_DONTWAIT|MSG_PEEK; + +/* we don't need these variants, we call kgio_autopush_send/recv directly */ +static inline void kgio_autopush_read(VALUE io) { } +static inline void kgio_autopush_write(VALUE io) { } + #else static const int peek_flags = MSG_PEEK; +# include +# if defined(TCP_NOPUSH) +static inline void kgio_autopush_read(VALUE io) { kgio_autopush_recv(io); } +static inline void kgio_autopush_write(VALUE io) { kgio_autopush_send(io); } +# endif #endif NORETURN(static void raise_empty_bt(VALUE, const char *)); @@ -112,6 +122,7 @@ static VALUE my_read(int io_wait, int argc, VALUE *argv, VALUE io) long n; prepare_read(&a, argc, argv, io); + kgio_autopush_read(io); if (a.len > 0) { set_nonblocking(a.fd); @@ -357,6 +368,8 @@ retry: n = (long)write(a.fd, a.ptr, a.len); if (write_check(&a, n, "write", io_wait) != 0) goto retry; + if (TYPE(a.buf) != T_SYMBOL) + kgio_autopush_write(io); return a.buf; } diff --git a/test/test_autopush.rb b/test/test_autopush.rb index 24b300f..57fbefa 100644 --- a/test/test_autopush.rb +++ b/test/test_autopush.rb @@ -38,7 +38,8 @@ class TestAutopush < Test::Unit::TestCase assert_nothing_raised { s.kgio_write 'asdf' } assert_equal :wait_readable, s.kgio_tryread(1) assert s.kgio_autopush? - assert_equal 1, s.getsockopt(Socket::IPPROTO_TCP, opt).unpack('i')[0] + val = s.getsockopt(Socket::IPPROTO_TCP, opt).unpack('i')[0] + assert_operator val, :>, 0, "#{opt}=#{val} (#{RUBY_PLATFORM})" end def test_autopush_true_unix -- 1.7.9.2.358.g22243