Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello, I have a bit of legacy code that I want to avoid changing as much as possible:

my $iaddr = &inet_aton("$sname") || return 5; socket(SH,PF_INET,SOCK_STREAM,getprotobyname('tcp')); connect(SH,sockaddr_in($port,$iaddr)) || return 6;

The issue is that I want to modify the amount of time that I am spending waiting for the connect before I timeout. I think that I can use setsockopt to do this. Reading the unix setsockopt (2) manpage (Using FreeBSD 4.1.1-STABLE), it appears that there are two variables associated with timeouts:

           SO_SNDTIMEO        set timeout value for output
           SO_RCVTIMEO        set timeout value for input

My Questions:

  1. Do either of these affect the timeout for a connect or do they only apply to connected sockets?
  2. If not, what is the correct way to set the connect timeout (if it can be done)?
  3. According to man setsockopt, these options require a timeval struct in c to work, what is the correct data structure to modify these options with the perl setsockopt?

Note: Yes, I know, I could do all this so much easier with IO::Socket, but let's just assume that is not an option here.


In reply to Setting timeout threshold when connecting to a socket. by ehdonhon

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-06-20 21:31 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.