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: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 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.raindrops.general Subject: [PATCH 3/3] Linux::TCP_Info: implement #get! instance method Date: Thu, 11 Apr 2013 23:28:24 +0000 Message-ID: <1365722904-889-3-git-send-email-normalperson@yhbt.net> References: <1365722904-889-1-git-send-email-normalperson@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: ger.gmane.org 1365722937 12606 80.91.229.3 (11 Apr 2013 23:28:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Apr 2013 23:28:57 +0000 (UTC) To: raindrops@librelist.org Original-X-From: raindrops@librelist.org Fri Apr 12 01:29:00 2013 Return-path: Envelope-to: gclrrg-raindrops@m.gmane.org List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: raindrops@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.raindrops.general:104 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UQQvM-0001TG-Cy for gclrrg-raindrops@m.gmane.org; Fri, 12 Apr 2013 01:29:00 +0200 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 50A8C73DBB for ; Thu, 11 Apr 2013 23:29:17 +0000 (UTC) This allows reusing existing Linux::TCP_Info objects to avoid generating garbage. --- ext/raindrops/linux_tcp_info.c | 1 + test/test_linux_tcp_info.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ext/raindrops/linux_tcp_info.c b/ext/raindrops/linux_tcp_info.c index ce1c2d3..dcdb153 100644 --- a/ext/raindrops/linux_tcp_info.c +++ b/ext/raindrops/linux_tcp_info.c @@ -131,6 +131,7 @@ void Init_raindrops_linux_tcp_info(void) cTCP_Info = rb_define_class_under(cRaindrops, "TCP_Info", rb_cObject); rb_define_alloc_func(cTCP_Info, alloc); rb_define_private_method(cTCP_Info, "initialize", init, 1); + rb_define_method(cTCP_Info, "get!", init, 1); #define TCPI_DEFINE_METHOD(x) \ rb_define_method(cTCP_Info, #x, tcp_info_##x, 0) diff --git a/test/test_linux_tcp_info.rb b/test/test_linux_tcp_info.rb index 3b4a245..c947211 100644 --- a/test/test_linux_tcp_info.rb +++ b/test/test_linux_tcp_info.rb @@ -12,6 +12,7 @@ class TestLinuxTCP_Info < Test::Unit::TestCase # Linux kernel commit 5ee3afba88f5a79d0bff07ddd87af45919259f91 TCP_INFO_useful_listenq = `uname -r`.strip >= '2.6.24' + def test_tcp_server s = TCPServer.new(TEST_ADDR, 0) rv = Raindrops::TCP_Info.new s @@ -23,6 +24,11 @@ def test_tcp_server a = s.accept tmp = Raindrops::TCP_Info.new s assert_equal 0, tmp.unacked + before = tmp.object_id + + tmp.get!(s) + assert_equal before, tmp.object_id + ensure c.close if c a.close if a @@ -35,6 +41,7 @@ def test_accessors tcp_info_methods = tmp.methods - Object.new.methods assert tcp_info_methods.size >= 32 tcp_info_methods.each do |m| + next if m.to_sym == :get! val = tmp.__send__ m assert_kind_of Integer, val assert val >= 0 -- 1.8.2.279.g631bc94