pittstown has asked for the wisdom of the Perl Monks concerning the following question:
If I use the basic Socket methods and raw field descriptors, (i.e.
everything is great; threads come, threads go, the server keeps on chugging.socket(SERVER, PF_INET, SOCK_STREAM, $proto); . . . while ($paddr = accept(USER, SERVER)) { . . . $thr = threads->create($sub_name, \*USER); . . . }
However, I'd like to use IO:Socket:INET, like this:
The problem is that when the $sub_name thread returns (NOT exits), I reach the Die and see: "END ServerAccept(), Software caused connection abort", which is obviously a Bad Thing.my $ServerSocket = new IO::Socket::INET ( LocalPort => $port, Listen => 2, Type => SOCK_STREAM, Reuse => 1, Proto => 'tcp' ); ... while ($clientSocket = $ServerSocket->accept()) { . . . $thr = threads->create( $sub_name, $clientSocket); . . . } Die "END ServerAccept(), $!";
If I put in a huge sleep in $sub_name just before returning, other threads can come in, so I'm pretty sure it is the thread cleanup that is closing the server socket. So the question is - how do I prevent this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Server socket closed when thread returns
by liverpole (Monsignor) on Jan 19, 2007 at 00:01 UTC |