<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">news.utdallas.edu!convex!tchrist Thu Feb 25 11:52:17 CST 1993
Article: 1074 of comp.lang.perl
Xref: feenix.metronet.com comp.lang.perl:1074
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.utdallas.edu!convex!tchrist
From: Tom Christiansen &lt;tchrist@convex.COM&gt;
#Subject: Re: SUMMARY: Timeout on Connect
Originator: tchrist@pixel.convex.com
Sender: usenet@news.eng.convex.com (news access account)
Message-ID: &lt;1993Feb18.040748.27347@news.eng.convex.com&gt;
Date: Thu, 18 Feb 1993 04:07:48 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
References: &lt;1luq98INN7di@gap.caltech.edu&gt;
Nntp-Posting-Host: pixel.convex.com
Organization: Convex Computer Corporation, Colorado Springs, CO
Keywords: Summary, sockets, connect, timeouts
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.
Lines: 38

&gt;From the keyboard of jack@ccsf.caltech.edu (Jack Stewart):
:There doesn't appear to be a way to make some sort of magic syscall to
:change the timeouts on the connect function either in C or perl.
:However the method that worked best for me was to fork a child and do
:all of the socket operations (including IO) within that child.  I
:could then kill the child if it had not finished in time.  

:    if (!socket(S,$AF_INET,$SOCK_STREAM,$proto)) {die "$!\n;"}
:    if (!bind(S,$this)) {die "$!\n;"}
:    if (connect(S,$primary)) {

You don't have to use an extra process to zap the connect.  As when
you're timing out reads, send yourself an alarm.  Here's how I might 
do it:

    $TIMEOUT = 15;
    sub Timer { die "Alarm Clock" }
    $SIG{ALRM} = Timer;

    socket(S, &amp;AF_INET, &amp;SOCK_STREAK, $proto)   || die "socket: $!";
    bind (S, $this)                             || die "bind: $!";

    eval {
        alarm($TIMEOUT);
        connect(S, $primary)                    || die "connect: $!";
        alarm(0);
    }; 

    if ($@ &amp;&amp; $@ !~ /Alarm Clock/) {
        die $@;
    } 

--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist


    The debate rages on: Is PL/I Bachtrian or Dromedary?


</pre></body></html>