zwon has asked for the wisdom of the Perl Monks concerning the following question:
I used to set timeout on socket with the following code:
my $timeout = pack( 'L!L!', $seconds, 0 ); defined $socket->sockopt( SO_RCVTIMEO, $timeout ) or die "Couldn't set timeout: $!";
And it worked just fine till they released NetBSD 6.0. It uses 64-bit time_t on all architectures, so I'm getting failures from cpan testers for NetBSD 6.0 on i386. Now I'm looking for a new elegant way to pack timeval. I can easily do it in C:
But I don't see any way to get size of time_t using pure Perl, it seems Config doesn't provide this parameter.use 5.010; use strict; use warnings; use Inline C => 'DATA'; my $timeval = pack_timeval(2,0); __DATA__ __C__ SV* pack_timeval(time_t tv_sec, long tv_usec) { struct timeval tv; tv.tv_sec = tv_sec; tv.tv_usec = tv_usec; return newSVpv((char *) &tv, sizeof(struct timeval)); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Packing struct timeval
by Anonymous Monk on Nov 24, 2012 at 11:00 UTC | |
by zwon (Abbot) on Nov 24, 2012 at 15:52 UTC | |
by Anonymous Monk on Nov 25, 2012 at 10:49 UTC | |
by zwon (Abbot) on Nov 25, 2012 at 14:29 UTC |
Back to
Seekers of Perl Wisdom