[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Socket Pipe II

Well, working on this some more I came up with a solution of my own that I
thought might work. Set a timeout (this probably occurred to you all
already, but my mail from this list comes slowly so I can't be sure =) on
the send and recieve requests- wait for a second for one, and if it doesn't
come wait for a second for the other. If that hasn't sent anything, go back
and wait for the first, etc.

Well, I've got a problem. I took this example right from the documentation,
and modified it only slightly:

eval {
	local $SIG{ALRM} = sub { die "alarm\n" };       # NB \n required
	alarm 5;		# Edited: changed to 5
	<STDIN>;		# Edited: variable time to wait, so alarms
				# can be triggered or not
	print alarm 0 . "\n";	# Print out value of alarm as it's set to 0
die if $@ && $@ ne "alarm\n";	# propagate errors
if ($@) {
	print "Timed out.\n";
}else {
	print "Didn't time out.\n";

Here's the catch, my output:

Didn't time out.

Didn't time out.
# alarm
File 'Corinth:Desktop Folder:Alarm Test'; Line 7
Didn't time out.
Didn't time out.
Didn't time out.
Didn't time out.

For the first two, I hit enter before my time ran out. After that I let the
time run down, and the alarm was tripped. Then, upon rerunning the script
(remember that it had finished, but I hadn't quit yet), I found that even
when I didn't allow the alarm to time out the immidiate output was the two
lines that are repeated, one for every enter I hit. If I quit macperl and
open it again, the alarms work until they time out.

I could speculate as to why this doesn't work, but I'm hoping someone on
the list knows why so that I don't have to look like a fool being wrong. ;)
If there's another way of doing this (short of writing another program to
fake the alarm with applescript or something- I'd like a perl-only solution
if it's possible) please let me know.


- strider


Therefore we do not lose heart. Though outwardly we are wasting away,
yet inwardly we are being renewed day by day. For our light and momentary
troubles are achieving for us an eternal glory that far outweighs them all.

2 Corinthians 4:16, 17


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org