[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Problem: using perl IO::Socket::INET and $SIG{ALRM}

Posted on 2004-12-01
Medium Priority
Last Modified: 2012-06-27
Is it possible to use $SIG{ALRM} together with IO::Socket::INET tcp server? Seems that triggered alarm functions cause accept to end with error, for example:


use IO::Socket::INET;

my %sock_parm;
$sock_parm{Type}      = SOCK_STREAM;
$sock_parm{Proto}     = "tcp";
$sock_parm{LocalPort} = 8080;
$sock_parm{Listen}    = SOMAXCONN;
$sock_parm{Reuse}     = 1;

my $sock = new IO::Socket::INET(%sock_parm);

sub tick {
  print "Tick!\n";

$SIG{ALRM} = \&tick;

print "Waiting...\n";
my $client = $sock->accept() || print "Failure!\n";
print "Done.\n";
Question by:Ivanov_G
  • 2
LVL 38

Expert Comment

ID: 12719791

You might want to post your question at
which is Perl specific.

LVL 85

Accepted Solution

ozo earned 1000 total points
ID: 12723734
my $client;
1 until $client = $sock->accept() || ($!ne"Interrupted system call"&&print "Fai\
lure! $!\n");
LVL 12

Author Comment

ID: 12734980
Hi ozo,
thanks for your reply, the solution you suggest seems to work OK. Anyway, accept still gets interrupded:

use POSIX;
my $client;
print "." until $client = $sock->accept() || ($! != EINTR&&print "Failure! $!\n");

Do you know the actual reason why $SIG{ALRM} interrupts accept?
I think this is not perl related problem and similar program in C++ for example will most probably behave exactly the same way?
LVL 85

Expert Comment

ID: 12742380
C will behave the same way.

     4 EINTR Interrupted function call.  An asynchronous signal (such as
             SIGINT or SIGQUIT) was caught by the process during the execution
             of an interruptible function. If the signal handler performs a
             normal return, the interrupted function call will seem to have
             returned the error condition.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question