<?xml version="1.0" encoding="windows-1252"?>
<node id="1005355" title="Packing struct timeval" created="2012-11-24 05:16:16" updated="2012-11-24 05:16:16">
<type id="115">
perlquestion</type>
<author id="715263">
zwon</author>
<data>
<field name="doctext">
&lt;p&gt;I used to set timeout on socket with the following code:
&lt;c&gt;
my $timeout = pack( 'L!L!', $seconds, 0 );
defined $socket-&gt;sockopt( SO_RCVTIMEO, $timeout )
  or die "Couldn't set timeout: $!";
&lt;/c&gt;
&lt;p&gt;And it worked just fine till they released [http://www.netbsd.org/releases/formal-6/NetBSD-6.0.html#major-changes | 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 &lt;em&gt;elegant&lt;/em&gt; way to pack timeval. I can easily do it in C:
&lt;c&gt;
use 5.010;
use strict;
use warnings;

use Inline C =&gt; '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 *) &amp;tv, sizeof(struct timeval));
}
&lt;/c&gt;
But I don't see any way to get size of time_t using pure Perl, it seems [mod://Config] doesn't provide this parameter.</field>
</data>
</node>
