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 #Subject: Re: SUMMARY: Timeout on Connect Originator: tchrist@pixel.convex.com Sender: usenet@news.eng.convex.com (news access account) Message-ID: <1993Feb18.040748.27347@news.eng.convex.com> Date: Thu, 18 Feb 1993 04:07:48 GMT Reply-To: tchrist@convex.COM (Tom Christiansen) References: <1luq98INN7di@gap.caltech.edu> 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 >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, &AF_INET, &SOCK_STREAK, $proto) || die "socket: $!"; bind (S, $this) || die "bind: $!"; eval { alarm($TIMEOUT); connect(S, $primary) || die "connect: $!"; alarm(0); }; if ($@ && $@ !~ /Alarm Clock/) { die $@; } --tom -- Tom Christiansen tchrist@convex.com convex!tchrist The debate rages on: Is PL/I Bachtrian or Dromedary? .