summaryrefslogtreecommitdiff
path: root/ext/socket/ancdata.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-24 10:56:57 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-24 10:56:57 +0000
commite137e939b7922044994f1fd8ea96b9e9b2a6b665 (patch)
treeb11968b7c41919c991e7c2cc9a97ca7d835c1216 /ext/socket/ancdata.c
parentb404c651d2e732fa25e0c009892682a7718d0d2a (diff)
* ext/socket/ancdata.c (ancillary_timestamp): support SCM_BINTIME.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/ancdata.c')
-rw-r--r--ext/socket/ancdata.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 0761db6787..788e5307a8 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");