mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket/ancdata.c (inspect_timeval_as_abstime): new function.
(ancillary_inspect): use it for SO_TIMESTAMP. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0c95958c2d
commit
475a350df8
2 changed files with 30 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Feb 23 02:44:42 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/ancdata.c (inspect_timeval_as_abstime): new function.
|
||||
(ancillary_inspect): use it for SO_TIMESTAMP.
|
||||
|
||||
Mon Feb 23 02:26:44 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/option.c (inspect_timeval_as_interval): renamed from
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "rubysocket.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#if defined(HAVE_ST_MSG_CONTROL)
|
||||
static VALUE rb_cAncillaryData;
|
||||
|
||||
|
@ -698,6 +700,26 @@ anc_inspect_ipv6_pktinfo(int level, int type, VALUE data, VALUE ret)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(SO_TIMESTAMP)
|
||||
static int
|
||||
inspect_timeval_as_abstime(int level, int optname, VALUE data, VALUE ret)
|
||||
{
|
||||
if (RSTRING_LEN(data) == sizeof(struct timeval)) {
|
||||
struct timeval s;
|
||||
struct tm tm;
|
||||
char buf[32];
|
||||
memcpy((char*)&s, RSTRING_PTR(data), sizeof(s));
|
||||
tm = *localtime(&s.tv_sec);
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
|
||||
rb_str_catf(ret, " %s.%06ld", buf, (long)s.tv_usec);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ancillarydata.inspect => string
|
||||
|
@ -768,6 +790,9 @@ ancillary_inspect(VALUE self)
|
|||
# if defined(SOL_SOCKET)
|
||||
case SOL_SOCKET:
|
||||
switch (type) {
|
||||
# if defined(SO_TIMESTAMP) /* GNU/Linux, MacOS X, Solaris */
|
||||
case SO_TIMESTAMP: inspected = inspect_timeval_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
|
||||
|
|
Loading…
Add table
Reference in a new issue