Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > $SIG{IO} example

Reply
Thread Tools

$SIG{IO} example

 
 
Sébastien Cottalorda
Guest
Posts: n/a
 
      11-29-2004
Hi all,

I'm planning to make a script that, on socket reception, do reception, but
the rest of time do something else.

#================================================= =====================
#!/usr/bin/perl -w
use IO::Select;
use IO::Socket;
unless ($socket = IO::Socket::INET->new(PeerAddr=> $adr_ip,
PeerPort=> $port,
Proto=> "tcp",
Timeout=>10,
Type=> SOCK_STREAM)){
die "Unable to create a tcp server $!";
}
$s->add($socket);
$SIG{IO}=\$do_reception;
while(1) {
#
# do something ...
# even sending datas throught the socket
#
}

sub do_reception{
if ($s->can_read(10)){
&logmsg("Reception ...\n");
if (defined $socket->recv($data_work,1024,0)){
print "< $data_work\n";
}
else {
print "Unable to receive\n";
}
}
else {
print "Timeout Receiving\n";
}
}


I've made that but it doesn't seem to work.
Do you have a SIG{IO} exemple program

Thanks in advance for any kind of help.

Sébastien Cottalorda

--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      11-29-2004
Sébastien Cottalorda <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Hi all,
>
> I'm planning to make a script that, on socket reception, do reception, but
> the rest of time do something else.


[...]

> $SIG{IO}=\$do_reception;


What makes you think $SIG{IO} does anything useful?

Anno
 
Reply With Quote
 
 
 
 
Sébastien Cottalorda
Guest
Posts: n/a
 
      11-29-2004
Anno Siegel wrote:

> Sébastien Cottalorda <(E-Mail Removed)> wrote in
> comp.lang.perl.misc:
>> Hi all,
>>
>> I'm planning to make a script that, on socket reception, do reception,
>> but the rest of time do something else.

>
> [...]
>
>> $SIG{IO}=\$do_reception;

>
> What makes you think $SIG{IO} does anything useful?
>
> Anno


Someone, who as used SIG{IO} in C programming, told me that catching that
signal can solve my problem.

How can I manage to do want I need ?
using IO::Select to check, in non blocking mode, if I can read ?

Thanks for you help.

Sébastien Cottalorda


--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      11-29-2004
Sébastien Cottalorda <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Sébastien Cottalorda <(E-Mail Removed)> wrote in
> > comp.lang.perl.misc:
> >> Hi all,
> >>
> >> I'm planning to make a script that, on socket reception, do reception,
> >> but the rest of time do something else.

> >
> > [...]
> >
> >> $SIG{IO}=\$do_reception;

> >
> > What makes you think $SIG{IO} does anything useful?
> >
> > Anno

>
> Someone, who as used SIG{IO} in C programming, told me that catching that
> signal can solve my problem.


Huh? SIGIO doesn't exist on any system I know.

> How can I manage to do want I need ?
> using IO::Select to check, in non blocking mode, if I can read ?


Read perldoc IO::Select. If you have specific questions, ask.

Anno
 
Reply With Quote
 
Christopher Nehren
Guest
Posts: n/a
 
      11-29-2004
On 2004-11-29, Anno Siegel scribbled these
curious markings:
> Huh? SIGIO doesn't exist on any system I know.


% kill -l
hup int quit ill trap abrt emt fpe kill bus segv sys pipe alrm term urg
stop tstp cont chld ttin ttou io xcpu xfsz vtalrm prof winch info usr1
^^
usr2
% uname -rs
FreeBSD 5.3-STABLE

Same on OpenBSD 3.6-STABLE, except tr[a-z][A-Z].

--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
Linux: "How rebellious ... in a conformist sort of way."
Unix is user friendly. However, it isn't idiot friendly.
 
Reply With Quote
 
Sébastien Cottalorda
Guest
Posts: n/a
 
      11-29-2004
Anno Siegel wrote:

> Sébastien Cottalorda <(E-Mail Removed)> wrote in
> comp.lang.perl.misc:
>> Anno Siegel wrote:
>>
>> > Sébastien Cottalorda <(E-Mail Removed)> wrote in
>> > comp.lang.perl.misc:
>> >> Hi all,
>> >>
>> >> I'm planning to make a script that, on socket reception, do reception,
>> >> but the rest of time do something else.
>> >
>> > [...]
>> >
>> >> $SIG{IO}=\$do_reception;
>> >
>> > What makes you think $SIG{IO} does anything useful?
>> >
>> > Anno

>>
>> Someone, who as used SIG{IO} in C programming, told me that catching that
>> signal can solve my problem.

>
> Huh? SIGIO doesn't exist on any system I know.
>
>> How can I manage to do want I need ?
>> using IO::Select to check, in non blocking mode, if I can read ?

>
> Read perldoc IO::Select. If you have specific questions, ask.
>
> Anno


# uname -a
Linux pc_seb 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686 unknown
unknown GNU/Linux

# kill -l
[snip]
29) SIGIO
[snip]

My program is a real time program:
- it need to receive asynchronous datas and reply immediately.
- it need to send regularily datas throught the socket (equipment check)
My problem is:
* If I wait for reading datas, I cannot send regularily anymore.
* If I make a non blocking loop:
while (1) {
if ($s->can_read(1)){
# ...
}
if ($s->can_write(1)){
# process that can take time
}
}
I'm frightened to make a infinite loop if I did'nt have nothing to send and
if I don't have to receive something.
That solution could not work either because if I take too long time to send
datas, I lost the real time on the reception.
That's why the best idea is, if possible, to catch a signal (I though
SIG{IO}), and make the reception immediately, then return to the normal
process.

Regards

Sebastien Cottalorda


--
[ retirer NOSPAM pour répondre directement
remove NOSPAM to reply directly ]
 
Reply With Quote
 
Arndt Jonasson
Guest
Posts: n/a
 
      11-29-2004

Christopher Nehren <(E-Mail Removed)> writes:
> On 2004-11-29, Anno Siegel scribbled these
> curious markings:
> > Huh? SIGIO doesn't exist on any system I know.

>
> % kill -l
> hup int quit ill trap abrt emt fpe kill bus segv sys pipe alrm term urg
> stop tstp cont chld ttin ttou io xcpu xfsz vtalrm prof winch info usr1
> ^^
> usr2
> % uname -rs
> FreeBSD 5.3-STABLE
>
> Same on OpenBSD 3.6-STABLE, except tr[a-z][A-Z].


For what it's worth, SIGIO exists on HP-UX and AIX too. Of course, it
remains the case that using SIGIO is not a portable way to do I/O.
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      11-29-2004
Arndt Jonasson <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>
> Christopher Nehren <(E-Mail Removed)> writes:
> > On 2004-11-29, Anno Siegel scribbled these
> > curious markings:
> > > Huh? SIGIO doesn't exist on any system I know.

> >
> > % kill -l
> > hup int quit ill trap abrt emt fpe kill bus segv sys pipe alrm term urg
> > stop tstp cont chld ttin ttou io xcpu xfsz vtalrm prof winch info usr1
> > ^^
> > usr2
> > % uname -rs
> > FreeBSD 5.3-STABLE
> >
> > Same on OpenBSD 3.6-STABLE, except tr[a-z][A-Z].

>
> For what it's worth, SIGIO exists on HP-UX and AIX too.


I see. I never noticed.

> Of course, it
> remains the case that using SIGIO is not a portable way to do I/O.


Maybe a good reason not to notice

Anno
 
Reply With Quote
 
Peter Wyzl
Guest
Posts: n/a
 
      11-29-2004
"Sébastien Cottalorda" <(E-Mail Removed)> wrote in message
news:41ab10da$0$2109$(E-Mail Removed)...
: Anno Siegel wrote:

<snip>
:
: My program is a real time program:
: - it need to receive asynchronous datas and reply immediately.
: - it need to send regularily datas throught the socket (equipment
check)
: My problem is:
: * If I wait for reading datas, I cannot send regularily anymore.
: * If I make a non blocking loop:
: while (1) {
: if ($s->can_read(1)){
: # ...
: }
: if ($s->can_write(1)){
: # process that can take time
: }
: }
: I'm frightened to make a infinite loop if I did'nt have nothing to
send and
: if I don't have to receive something.
: That solution could not work either because if I take too long time
to send
: datas, I lost the real time on the reception.
: That's why the best idea is, if possible, to catch a signal (I though
: SIG{IO}), and make the reception immediately, then return to the normal
: process.

I would approach this as two separate programs communicating with each other
with some form of IPC (perhaps even simple file updating).

The reading program can handle the 'instant response' and the writing
program can be regular.

Then I would look at possible threads (one for each task) or maybe a forked
process once I had the other part working fine.

--
Wyzelli


 
Reply With Quote
 
Scott W Gifford
Guest
Posts: n/a
 
      11-29-2004
Sébastien Cottalorda <(E-Mail Removed)> writes:

[...]

> I've made that but it doesn't seem to work.
> Do you have a SIG{IO} exemple program


You have to set the file descriptor to asynchronous to get SIGIO when
data becomes available. See the O_ASYNC flag in fcntl(2) and open(2).

IIRC, Stevens talks about this technique in Advanced Programming in
the Unix Environment, so you can find sample code in C there.

According to the manpages, this is specific to BSD-derived systems and
Linux.

----ScottG.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about 2 bit counter example. Skybuck Flying VHDL 3 08-03-2005 03:00 PM
Installer example in northwind or duwamish7? Bright ASP .Net 1 07-18-2005 05:50 PM
Shift register example? bob VHDL 1 02-18-2005 07:34 PM
'example.com' == 'example.com.' => false... is this intended? Sam Roberts Ruby 15 02-07-2005 04:36 PM
example designs for Xilinx System Generator ? Timo Dammes VHDL 2 06-11-2004 04:45 PM



Advertisments