Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v1_9_2_180) is shown here.
timestamp()
public
returns the timestamp as
a time object.
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
Addrinfo.udp("127.0.0.1", 0).bind {|s1|
Addrinfo.udp("127.0.0.1", 0).bind {|s2|
s1.setsockopt(:SOCKET, :TIMESTAMP, true)
s2.send "a", 0, s1.local_address
ctl = s1.recvmsg.last
p ctl
t = ctl.timestamp
p t
p t.usec
p t.nsec
}
}
static VALUE
ancillary_timestamp(VALUE self)
{
int level, type;
VALUE data;
VALUE result = Qnil;
level = ancillary_level(self);
type = ancillary_type(self);
data = ancillary_data(self);
# ifdef SCM_TIMESTAMP
if (level == SOL_SOCKET && type == SCM_TIMESTAMP &&
RSTRING_LEN(data) == sizeof(struct timeval)) {
struct timeval tv;
memcpy((char*)&tv, RSTRING_PTR(data), sizeof(tv));
result = rb_time_new(tv.tv_sec, tv.tv_usec);
}
# endif
# ifdef SCM_TIMESTAMPNS
if (level == SOL_SOCKET && type == SCM_TIMESTAMPNS &&
RSTRING_LEN(data) == sizeof(struct timespec)) {
struct timespec ts;
memcpy((char*)&ts, RSTRING_PTR(data), sizeof(ts));
result = rb_time_nano_new(ts.tv_sec, ts.tv_nsec);
}
# endif
#define add(x,y) (rb_funcall((x), '+', 1, (y)))
#define mul(x,y) (rb_funcall((x), '*', 1, (y)))
#define quo(x,y) (rb_funcall((x), rb_intern("quo"), 1, (y)))
# ifdef SCM_BINTIME
if (level == SOL_SOCKET && type == SCM_BINTIME &&
RSTRING_LEN(data) == sizeof(struct bintime)) {
struct bintime bt;
VALUE d, timev;
memcpy((char*)&bt, RSTRING_PTR(data), sizeof(bt));
d = ULL2NUM(0x100000000UL);
d = mul(d,d);
timev = add(TIMET2NUM(bt.sec), quo(ULL2NUM(bt.frac), d));
result = rb_time_num_new(timev, Qnil);
}
# endif
if (result == Qnil)
rb_raise(rb_eTypeError, "timestamp ancillary data expected");
return result;
}