summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-23 11:32:43 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-23 11:32:43 +0000
commit23e286f3fb1b7570e107b9a028c1fb03bacc5cca (patch)
treeda380e291a0f9163f15922fc46206289664e7bec /ext/socket
parenta0e3e8e4d134bc1b94d5d43d613e13606c9a94d8 (diff)
* ext/socket/ancdata.c (inspect_bintime_as_abstime): new function to
show struct bintime. (ancillary_inspect): use it for SCM_BINTIME on FreeBSD. * ext/socket/mkconstants.rb: define SCM_BINTIME. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/ancdata.c51
-rw-r--r--ext/socket/mkconstants.rb1
2 files changed, 52 insertions, 0 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 793c7ed5df..f902a67f56 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -722,6 +722,54 @@ inspect_timeval_as_abstime(int level, int optname, VALUE data, VALUE ret)
}
#endif
+#if defined(SCM_BINTIME)
+static int
+inspect_bintime_as_abstime(int level, int optname, VALUE data, VALUE ret)
+{
+ if (RSTRING_LEN(data) == sizeof(struct bintime)) {
+ struct bintime bt;
+ struct tm tm;
+ uint64_t frac_h, frac_l;
+ uint64_t scale_h, scale_l;
+ uint64_t tmp1, tmp2;
+ uint64_t res_h, res_l;
+ char buf[32];
+ memcpy((char*)&bt, RSTRING_PTR(data), sizeof(bt));
+ tm = *localtime(&bt.sec);
+ strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
+
+ /* res_h = frac * 10**19 / 2**64 */
+
+ frac_h = bt.frac >> 32;
+ frac_l = bt.frac & 0xffffffff;
+
+ scale_h = 0x8ac72304; /* 0x8ac7230489e80000 == 10**19 */
+ scale_l = 0x89e80000;
+
+ res_h = frac_h * scale_h;
+ res_l = frac_l * scale_l;
+
+ tmp1 = frac_h * scale_l;
+ res_h += tmp1 >> 32;
+ tmp2 = res_l;
+ res_l += tmp1 & 0xffffffff;
+ if (res_l < tmp2) res_h++;
+
+ tmp1 = frac_l * scale_h;
+ res_h += tmp1 >> 32;
+ tmp2 = res_l;
+ res_l += tmp1 & 0xffffffff;
+ if (res_l < tmp2) res_h++;
+
+ rb_str_catf(ret, " %s.%019"PRIu64, buf, res_h);
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+#endif
+
/*
* call-seq:
* ancillarydata.inspect => string
@@ -795,6 +843,9 @@ ancillary_inspect(VALUE self)
# if defined(SCM_TIMESTAMP) /* GNU/Linux, FreeBSD, NetBSD, OpenBSD, MacOS X, Solaris */
case SCM_TIMESTAMP: inspected = inspect_timeval_as_abstime(level, type, data, ret); break;
# endif
+# if defined(SCM_BINTIME) /* FreeBSD */
+ case SCM_BINTIME: inspected = inspect_bintime_as_abstime(level, type, data, ret); break;
+# endif
# if defined(SCM_RIGHTS) /* 4.4BSD */
case SCM_RIGHTS: inspected = anc_inspect_socket_rights(level, type, data, ret); break;
# endif
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index e2efc49295..fc39faf8e0 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -668,6 +668,7 @@ SCM_CREDS
SCM_TIMESTAMP
SCM_TIMESTAMPNS
SCM_UCRED
+SCM_BINTIME
LOCAL_PEERCRED
LOCAL_CREDS