kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* kgio, autopush test fails on Debian GNU/kFreeBSD
@ 2012-03-04 16:02 375gnu
  2012-03-05  8:43 ` Eric Wong
  0 siblings, 1 reply; 7+ messages in thread
From: 375gnu @ 2012-03-04 16:02 UTC (permalink / raw)
  To: kgio

I know that it's an exotic system, but anyway.

In the last assertion getsockopt returns 0. May be it's good behavior for
GNU/kFreeBSD, I don't know.

  def test_autopush_accessors
    Kgio.autopush = true
    opt = RUBY_PLATFORM =~ /freebsd/ ? TCP_NOPUSH : TCP_CORK
    s = Kgio::TCPSocket.new(@host, @port)
    assert_equal 0, s.getsockopt(Socket::IPPROTO_TCP, opt).unpack('i')[0]
    assert ! s.kgio_autopush?
    s.kgio_autopush = true
    assert s.kgio_autopush?
    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]
  end



-- 
https://375gnu.wordpress.com/
https://launchpad.net/~375gnu/+archive/ppa


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: kgio, autopush test fails on Debian GNU/kFreeBSD
  2012-03-04 16:02 kgio, autopush test fails on Debian GNU/kFreeBSD 375gnu
@ 2012-03-05  8:43 ` Eric Wong
  2012-03-05 18:59   ` 375gnu
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2012-03-05  8:43 UTC (permalink / raw)
  To: kgio

375gnu <375gnu@gmail.com> wrote:
> I know that it's an exotic system, but anyway.
> 
> In the last assertion getsockopt returns 0. May be it's good behavior for
> GNU/kFreeBSD, I don't know.

I think this problem is partially caused by eglibc/glibc failing to
define TCP_NOPUSH in the headers.   I can probably workaround it with
with something like:

#if defined(__GLIBC__) && defined(__FreeBSD_kernel__) && !defined(TCP_NOPUSH)
#  define TCP_NOPUSH 4
#endif

in ext/kgio/autopush.c   If it works, we should report this to the
Debian eglibc folks.

>   def test_autopush_accessors
>     Kgio.autopush = true
>     opt = RUBY_PLATFORM =~ /freebsd/ ? TCP_NOPUSH : TCP_CORK

And I suspect RUBY_PLATFORM is "gnu/kfreebsd" or something and
matches :x

I'll try to get this working on GNU/kFreeBSD this week if you don't beat
me to it.

It'd probably be a good idea to just add a Kgio.autopush_capable?
method to the API, to avoid problems like this in the future, too...


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: kgio, autopush test fails on Debian GNU/kFreeBSD
  2012-03-05  8:43 ` Eric Wong
@ 2012-03-05 18:59   ` 375gnu
  2012-03-05 23:45     ` Eric Wong
  0 siblings, 1 reply; 7+ messages in thread
From: 375gnu @ 2012-03-05 18:59 UTC (permalink / raw)
  To: kgio

On 3/5/12, Eric Wong <normalperson@yhbt.net> wrote:
>> In the last assertion getsockopt returns 0. May be it's good behavior for
>> GNU/kFreeBSD, I don't know.
>
> I think this problem is partially caused by eglibc/glibc failing to
> define TCP_NOPUSH in the headers.

No, /usr/include/netinet/tcp.h has definition for TCP_NOPUSH. There is a Debian
specific patch which defines it.


>>   def test_autopush_accessors
>>     Kgio.autopush = true
>>     opt = RUBY_PLATFORM =~ /freebsd/ ? TCP_NOPUSH : TCP_CORK
>
> And I suspect RUBY_PLATFORM is "gnu/kfreebsd" or something and
> matches :x

"x86_64-kfreebsd-gnu" on amd64


-- 
https://375gnu.wordpress.com/
https://launchpad.net/~375gnu/+archive/ppa


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: kgio, autopush test fails on Debian GNU/kFreeBSD
  2012-03-05 18:59   ` 375gnu
@ 2012-03-05 23:45     ` Eric Wong
  2012-03-05 23:47       ` [PATCH 1/3] accept4: require SOCK_NONBLOCK/SOCK_CLOEXEC macros Eric Wong
                         ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Eric Wong @ 2012-03-05 23:45 UTC (permalink / raw)
  To: kgio

375gnu <375gnu@gmail.com> wrote:
> On 3/5/12, Eric Wong <normalperson@yhbt.net> wrote:
> >> In the last assertion getsockopt returns 0. May be it's good behavior for
> >> GNU/kFreeBSD, I don't know.
> >
> > I think this problem is partially caused by eglibc/glibc failing to
> > define TCP_NOPUSH in the headers.
> 
> No, /usr/include/netinet/tcp.h has definition for TCP_NOPUSH. There is a Debian
> specific patch which defines it.

OK.  I've pushed out a 3 fixes to get this building on my
Debian GNU/kFreeBSD 6.0 KVM instance to "master" of
git://bogomips.org/kgio.git

      accept4: require SOCK_NONBLOCK/SOCK_CLOEXEC macros
      autopush: fix/enable under Debian GNU/kFreeBSD
      test: increase delta range for timing-sensitive test


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] accept4: require SOCK_NONBLOCK/SOCK_CLOEXEC macros
  2012-03-05 23:45     ` Eric Wong
@ 2012-03-05 23:47       ` Eric Wong
  2012-03-05 23:47       ` [PATCH 2/3] autopush: fix/enable under Debian GNU/kFreeBSD Eric Wong
  2012-03-05 23:47       ` [PATCH 3/3] test: increase delta range for timing-sensitive test Eric Wong
  2 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2012-03-05 23:47 UTC (permalink / raw)
  To: kgio

The check for the accept4() function actually succeeds on a
stock installation of Debian GNU/kFreeBSD 6.0, but the
eglibc headers fail to define the necessary flags.
---
 ext/kgio/missing_accept4.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ext/kgio/missing_accept4.h b/ext/kgio/missing_accept4.h
index 2801b5d..3e9ec67 100644
--- a/ext/kgio/missing_accept4.h
+++ b/ext/kgio/missing_accept4.h
@@ -1,4 +1,4 @@
-#ifndef HAVE_ACCEPT4
+#if !defined(HAVE_ACCEPT4) || !defined(SOCK_CLOEXEC) || !defined(SOCK_NONBLOCK)
 #  ifndef _GNU_SOURCE
 #    define _GNU_SOURCE
 #  endif
-- 
1.7.9.2.358.g22243



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] autopush: fix/enable under Debian GNU/kFreeBSD
  2012-03-05 23:45     ` Eric Wong
  2012-03-05 23:47       ` [PATCH 1/3] accept4: require SOCK_NONBLOCK/SOCK_CLOEXEC macros Eric Wong
@ 2012-03-05 23:47       ` Eric Wong
  2012-03-05 23:47       ` [PATCH 3/3] test: increase delta range for timing-sensitive test Eric Wong
  2 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2012-03-05 23:47 UTC (permalink / raw)
  To: kgio

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 <netinet/tcp.h>
+#  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



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] test: increase delta range for timing-sensitive test
  2012-03-05 23:45     ` Eric Wong
  2012-03-05 23:47       ` [PATCH 1/3] accept4: require SOCK_NONBLOCK/SOCK_CLOEXEC macros Eric Wong
  2012-03-05 23:47       ` [PATCH 2/3] autopush: fix/enable under Debian GNU/kFreeBSD Eric Wong
@ 2012-03-05 23:47       ` Eric Wong
  2 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2012-03-05 23:47 UTC (permalink / raw)
  To: kgio

This appears to be needed for Debian GNU/kFreeBSD under KVM.
---
 test/test_default_wait.rb |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/test_default_wait.rb b/test/test_default_wait.rb
index 55631fd..7137d0c 100644
--- a/test/test_default_wait.rb
+++ b/test/test_default_wait.rb
@@ -24,7 +24,7 @@ class TestDefaultWait < Test::Unit::TestCase
     t0 = Time.now
     assert_nil a.kgio_wait_readable(1.1)
     diff = Time.now - t0
-    assert_in_delta diff, 1.1, 0.05
+    assert_in_delta diff, 1.1, 0.2
 
     b.kgio_write '.'
     assert_equal a, a.kgio_wait_readable(1.1)
@@ -37,7 +37,7 @@ class TestDefaultWait < Test::Unit::TestCase
     t0 = Time.now
     assert_nil b.kgio_wait_writable(1.1)
     diff = Time.now - t0
-    assert_in_delta diff, 1.1, 0.05
+    assert_in_delta diff, 1.1, 0.2
 
     a.kgio_read(16384)
     assert_equal b, b.kgio_wait_writable(1.1)
-- 
1.7.9.2.358.g22243



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-03-05 23:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-04 16:02 kgio, autopush test fails on Debian GNU/kFreeBSD 375gnu
2012-03-05  8:43 ` Eric Wong
2012-03-05 18:59   ` 375gnu
2012-03-05 23:45     ` Eric Wong
2012-03-05 23:47       ` [PATCH 1/3] accept4: require SOCK_NONBLOCK/SOCK_CLOEXEC macros Eric Wong
2012-03-05 23:47       ` [PATCH 2/3] autopush: fix/enable under Debian GNU/kFreeBSD Eric Wong
2012-03-05 23:47       ` [PATCH 3/3] test: increase delta range for timing-sensitive test Eric Wong

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

	https://yhbt.net/kgio.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).