diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-24 10:56:57 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-24 10:56:57 +0000 |
commit | 933369b2527c465af7791692fbada9eb55d208c3 (patch) | |
tree | b11968b7c41919c991e7c2cc9a97ca7d835c1216 | |
parent | b02b853033d78525c17dcc25f7b130901d7fc67e (diff) | |
download | ruby-933369b2527c465af7791692fbada9eb55d208c3.tar.gz ruby-933369b2527c465af7791692fbada9eb55d208c3.tar.xz ruby-933369b2527c465af7791692fbada9eb55d208c3.zip |
* ext/socket/ancdata.c (ancillary_timestamp): support SCM_BINTIME.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@22594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | ext/socket/ancdata.c | 15 | ||||
-rw-r--r-- | test/socket/test_socket.rb | 10 |
3 files changed, 27 insertions, 2 deletions
@@ -1,3 +1,7 @@ +Tue Feb 24 19:56:11 2009 Tanaka Akira <akr@fsij.org> + + * ext/socket/ancdata.c (ancillary_timestamp): support SCM_BINTIME. + Tue Feb 24 19:45:15 2009 Tanaka Akira <akr@fsij.org> * ext/socket/ancdata.c (ancillary_timestamp): new method. diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index 0761db678..788e5307a 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -209,6 +209,10 @@ ancillary_unix_rights(VALUE self) * _ancillarydata_ should be one of following type: * - SOL_SOCKET/SCM_TIMESTAMP (micro second) GNU/Linux, FreeBSD, NetBSD, OpenBSD, Solaris, MacOS X * - SOL_SOCKET/SCM_TIMESTAMPNS (nano second) GNU/Linux + * - SOL_SOCKET/SCM_BINTIME (2**(-64) second) FreeBSD + * + * Note that Time cannot represent SCM_BINTIME timestamps accurately + * because Time uses nano second as internal representation. * * Addrinfo.udp("127.0.0.1", 0).bind {|s1| * Addrinfo.udp("127.0.0.1", 0).bind {|s2| @@ -253,6 +257,17 @@ ancillary_timestamp(VALUE self) } #endif +#ifdef SCM_BINTIME + if (level == SOL_SOCKET && type == SCM_BINTIME && + RSTRING_LEN(data) == sizeof(struct bintime)) { + struct bintime bt; + struct timespec ts; + memcpy((char*)&bt, RSTRING_PTR(data), sizeof(bt)); + bintime2timespec(&bt, &ts); + result = rb_time_nano_new(ts.tv_sec, ts.tv_nsec); + } +#endif + if (result == Qnil) rb_raise(rb_eTypeError, "timestamp ancillary data expected"); diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index e8b8959b4..b12baaebb 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -289,7 +289,9 @@ class TestSocket < Test::Unit::TestCase t2 = Time.now.strftime("%Y-%m-%d") pat = Regexp.union([t1, t2].uniq) assert_match(pat, stamp.inspect) - pat = /\.#{"%06d" % stamp.timestamp.usec}/ + t = stamp.timestamp + assert_match(pat, t.strftime("%Y-%m-%d")) + pat = /\.#{"%06d" % t.usec}/ assert_match(pat, stamp.inspect) end @@ -314,7 +316,9 @@ class TestSocket < Test::Unit::TestCase t2 = Time.now.strftime("%Y-%m-%d") pat = Regexp.union([t1, t2].uniq) assert_match(pat, stamp.inspect) - pat = /\.#{"%09d" % stamp.timestamp.nsec}/ + t = stamp.timestamp + assert_match(pat, t.strftime("%Y-%m-%d")) + pat = /\.#{"%09d" % t.nsec}/ assert_match(pat, stamp.inspect) end @@ -334,6 +338,8 @@ class TestSocket < Test::Unit::TestCase t2 = Time.now.strftime("%Y-%m-%d") pat = Regexp.union([t1, t2].uniq) assert_match(pat, stamp.inspect) + t = stamp.timestamp + assert_match(pat, t.strftime("%Y-%m-%d")) end end if defined?(Socket) |