in reply to Re^3: Trying to thread a daemon with threads and Thread::Queue
in thread Trying to thread a daemon with threads and Thread::Queue
From: perldoc on shutdown()shutdown $socket, 2;
Basically the while ( $Qclean->pending ) is not immediately triggerd (to close the socket in the main accept thread) because it is inside the while ( ... $sock->accept() ), and won't happen until another client connects, so the first client will just hang because it sees the socket on the server is still open.while ( my ($new_sock, $clientAddr) = $sock->accept() ) { my ( $clientPort, $clientIp ) = sockaddr_in( $clientAddr ); # put the connection on the queue for a reader thread my $fno = fileno($new_sock); $sockets{ $fno } = $new_sock; $Q->enqueue( "$fno\0$clientIp" ); while ( $Qclean->pending ) { my $fileno = $Qclean->dequeue(); $log->warning("Attempting to close handle associated with file +no: $fileno"); close $sockets{ $fileno }; delete $sockets{ $fileno }; } }
After re-adding the shutdown() line before close() in the handleConnection() sub to avoid the script blowing up because of SIGPIPE:SIG{PIPE}='IGNORE';
But then the client doesn't get the response (what is written on the socket by the server thread from the handleConnection() sub), just a connection drop :Sshutdown $socket, 2; close $socket;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Trying to thread a daemon with threads and Thread::Queue
by BrowserUk (Patriarch) on Aug 29, 2008 at 15:07 UTC |