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

Re: [MacPerl] Socket Pipe II

On Wed, Jun 23, 1999 at 03:13:20PM -0400, strider corinth wrote:
> 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.

Actually, that is not the solution that occured to me...  My suggestion is

> 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

This sets an alarm of "0\n".  I don't think that's what you meant to do.

print alarm(0) . "\n";

> };
> 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:
> 71582784
> Didn't time out.
> 71582784
> Didn't time out.
> # alarm
> 	...propagated.
> File 'Corinth:Desktop Folder:Alarm Test'; Line 7
> 71582783
> Didn't time out.
> 71582783
> Didn't time out.
> 71582783
> Didn't time out.
> 71582783
> Didn't time out.

Given the error above, I'm not sure where those newlines after the numbers
are coming from.  Was this output produced by the above code?

> 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.

Those values returned by alarm don't seem to make sense.  How can you set
an alarm of 5, and then have 71582783 seconds left when you reset the alarm
to 0?  Maybe this is some quirk of alarm() in MacPerl.

> 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.

Don't use alarms.  Use four-argument select() [or the IO::Select module].


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