about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-01-18 10:50:28 +0000
committerEric Wong <normalperson@yhbt.net>2013-01-18 10:50:28 +0000
commit3e555a62c75406d15199fd7bdb287704e5738352 (patch)
tree14e6a5b4f3e629fb74ae9cd00f72005cb59b4857
parentc751f42f5f6a5e54a399df472015ab6d2ffc3f7a (diff)
downloadkgio-3e555a62c75406d15199fd7bdb287704e5738352.tar.gz
rename fastopen => kgio_fastopen in Kgio::Socket
In the unlikely case the Ruby Socket class implements its
own "fastopen" method, we will avoid conflicting.
-rw-r--r--ext/kgio/connect.c9
-rw-r--r--test/test_tfo.rb8
2 files changed, 10 insertions, 7 deletions
diff --git a/ext/kgio/connect.c b/ext/kgio/connect.c
index 07ea79c..63c0bbc 100644
--- a/ext/kgio/connect.c
+++ b/ext/kgio/connect.c
@@ -169,13 +169,16 @@ static VALUE tfo_sendto(void *_a)
  *
  *        s = Kgio::Socket.new(:INET, :STREAM)
  *        addr = Socket.pack_sockaddr_in(80, "example.com")
- *        s.fastopen("hello world", addr) -> nil
+ *        s.kgio_fastopen("hello world", addr) -> nil
  *
  * Starts a TCP connection using TCP Fast Open.  This uses a blocking
  * sendto() syscall and is only available on Ruby 1.9 or later.
  * This raises exceptions (including Errno::EINPROGRESS/Errno::EAGAIN)
  * on errors.  Using this is only recommended for blocking sockets.
- *         s.setsockopt(:SOCKET, :SNDTIMEO, [1,0].pack("l_l_"))
+ *
+ * Timeouts may be set with setsockopt:
+ *
+ *        s.setsockopt(:SOCKET, :SNDTIMEO, [1,0].pack("l_l_"))
  */
 static VALUE fastopen(VALUE sock, VALUE buf, VALUE addr)
 {
@@ -379,7 +382,7 @@ void init_kgio_connect(void)
         rb_define_singleton_method(cKgio_Socket, "connect", kgio_connect, 1);
         rb_define_singleton_method(cKgio_Socket, "start", kgio_start, 1);
 #if defined(MSG_FASTOPEN) && defined(HAVE_RB_THREAD_BLOCKING_REGION)
-        rb_define_method(cKgio_Socket, "fastopen", fastopen, 2);
+        rb_define_method(cKgio_Socket, "kgio_fastopen", fastopen, 2);
 #endif
         /*
          * Document-class: Kgio::TCPSocket
diff --git a/test/test_tfo.rb b/test/test_tfo.rb
index 846e273..5ab208d 100644
--- a/test/test_tfo.rb
+++ b/test/test_tfo.rb
@@ -33,7 +33,7 @@ class TestTFO < Test::Unit::TestCase
     port = s.local_address.ip_port
     addr = Socket.pack_sockaddr_in(port, addr)
     c = Kgio::Socket.new(:INET, :STREAM)
-    assert_nil c.fastopen("HELLO", addr)
+    assert_nil c.kgio_fastopen("HELLO", addr)
     a = s.accept
     assert_equal "HELLO", a.read(5)
     c.close
@@ -41,7 +41,7 @@ class TestTFO < Test::Unit::TestCase
 
     # ensure empty sends work
     c = Kgio::Socket.new(:INET, :STREAM)
-    assert_nil c.fastopen("", addr)
+    assert_nil c.kgio_fastopen("", addr)
     a = s.accept
     Thread.new { c.close }
     assert_nil a.read(1)
@@ -56,14 +56,14 @@ class TestTFO < Test::Unit::TestCase
       assert_equal buf.size, a.read(buf.size).size
       a.close
     end
-    assert_nil c.fastopen(buf, addr)
+    assert_nil c.kgio_fastopen(buf, addr)
     thr.join
     c.close
 
     # allow timeouts
     c = Kgio::Socket.new(:INET, :STREAM)
     c.setsockopt(:SOCKET, :SNDTIMEO, [ 0, 10 ].pack("l_l_"))
-    unsent = c.fastopen(buf, addr)
+    unsent = c.kgio_fastopen(buf, addr)
     c.close
     assert_equal s.accept.read.size + unsent.size, buf.size
   end if defined?(Addrinfo) && defined?(Kgio::TCP_FASTOPEN)