Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6887443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:53:08+00:00 2026-05-27T05:53:08+00:00

If I try like this: my $sock = IO::Socket::INET->new( … ) or die no

  • 0

If I try like this:

my $sock = IO::Socket::INET->new( … )                    or die "no socket for you";
defined $sock->setsockopt(SOL_SOCKET, SO_RCVTIMEO, 30)   or die "setsockopt: $!";

then my script suffers death from “setsockopt: Invalid argument at [line 2]”. The IO::Socket and perlfunc pods do not say, though perlfunc gives an example with TCP_NODELAY which makes it look like the above should work.

(quick note: I’ve answered my own question, as best I can, but certainly welcome a better answer. The most obvious “better” would be for it to be portable, at least on POSIX machines)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:53:09+00:00Added an answer on May 27, 2026 at 5:53 am

    By using strace on the Perl interpreter running the script, it becomes clear that the problem is that Perl isn’t packing a struct timeval (required by SO_RCVTIMEO) for you. Further, there do not appear to be helper functions to do it for you. Instead, you must do it yourself.

    This turns out to be problematic because struct timeval is machine-specific. The Single Unix Specification defines it:

    The <sys/time.h> header shall define the timeval structure, which
    shall include at least the following members:

    time_t         tv_sec        Seconds.
    suseconds_t    tv_usec       Microseconds.
    

    It also says that time_t is an integer or real-floating type, and "suseconds_t shall be a signed integer type capable of storing values at least in the range [-1, 1000000]" (see sys/types.h).

    Without access to the C structure, it isn’t possible to do this portably. But if we assume glibc, that has a more restrictive definition, specifying both as long, and that they’re the only two members. However, this is a documentation bug. So never mind.

    So, the best I can do, which I believe works on both GNU/Linux IA-32 and GNU/Linux AMD64, is this:

    $sock->setsockopt(SOL_SOCKET, SO_RCVTIMEO, pack('l!l!', 30, 0))
        or die "setsockopt: $!";
    

    The pack format l! means to use the current machine’s native long—which is what the glibc docs say, and is apparently implemented for at least some glibc architectures (but not SPARC, according to the bug).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get twitter updates like this: try { $doc = new
I'm requesting a webpage with sockets like this: Socket sock = null; PrintWriter out
I would try something like this but it isn't allowed. function GetDynamicModulesProperties() { var
I'm bored with surrounding code with try catch like this.. try { //some boring
Using something like this: try: # Something... except Exception as excep: logger = logging.getLogger(component)
I saw some code like this: try { db.store(mydata); } finally { db.cleanup(); }
Often I find myself coming across code like this: try { StreamWriter strw =
When parsing an xml file in android, I'm doing like this: try { InputStream
try to set host in dsn of pdo like this: <?php /* Connect to
The dillema is like this: If I try to fit all the scripts blocks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.