|We don't bite newbies here... much|
IO::Socket::INET, threads, and screwy recv() resultsby jettero (Monsignor)
|on Jan 03, 2006 at 19:28 UTC||Need Help??|
jettero has asked for the
wisdom of the Perl Monks concerning the following question:
I have a socket that I wish to use from two threads. It's not a Listen socket. My &listener dies after a while though. This death is reliable, though you can't really say when before hand. If I do the same test without threads it works fine, so I figure I need to dup the IO::Socket. The problem with tye's "<&".fileno($sock) is that it returns an IO::Handle, and I wish to call the connected() from IO::Socket later.
Please help. Here is a small sample of what I'm trying to do:
I also realize there are modules like Net::Telnet that do a lot of this stuff for you, but I wish to learn how to do this by hand.
UPDATE (several hours later): It doesn't die at all, the recv() quits stuffing data into $msg though. It doesn't return undef either, as it would if there were an error, and it stays connected() because it starts looping really fast through the while(). I guess I have no idea why the code above doesn't work.
UPDATE II (1/5/6): I changed the code above around a little. This code actually does work as an IGS client. However, very occasionally the recv() will begin to get 0 results back and the while() loop starts firing a billion times a second (never to recover). This happens more frequently with a version where I pass fileno() and $newiosocket->fdopen($fileno, "+>") in each thread instead.