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

x
?
Solved

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

Posted on 2004-12-01
4
Medium Priority
?
1,747 Views
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:

#!/usr/bin/perl

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";
  alarm(5);
}

$SIG{ALRM} = \&tick;
alarm(5);


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

Expert Comment

by:wesly_chen
ID: 12719791
Hi,

You might want to post your question at
http://www.experts-exchange.com/Programming/Programming_Languages/Perl/
which is Perl specific.

Wesly
0
 
LVL 85

Accepted Solution

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

Author Comment

by:Ivanov_G
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?
0
 
LVL 85

Expert Comment

by:ozo
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.
0

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