Hi! THanks for your suggestion.
I changed my code to: sub _read_from_socket{ my ($select) = @_; my ($output, $buffer) = ('', ''); my $socket = undef; do { $socket = ($select->can_read(0.1))[0]; } while (!defined $socket); while(1){ my $status = $socket->read($buffer, 1); die "Error: $!" if(!defined $status); $output .= $buffer; last if $output =~ /\r\n$|^\z/; } return $output; } Unfortunatelly i'm still getting connections "hanged". This time, according to wireshark it's when there's a TCP retransmission of a [FIN,ACK]: Remote [FIN,ACK] -> Local Local [FIN,ACK] -> Remote Remote [ACK] -> Local Remote [ACK] -> Local Local [FIN, ACK] -> Remote (TCP Retransmission) Local [FIN, ACK] -> Remote (TCP Retransmission) Local [FIN, ACK] -> Remote (TCP Retransmission) Remote [SYN, ACK] -> Local (TCP Spurious Retransmission) Local [ACK] -> Remote (TCP Dup Ack #5) Local [FIN, ACK] -> Remote (TCP Retransmission) Local [FIN, ACK] -> Remote (TCP Retransmission) Local [FIN, ACK] -> Remote (TCP Retransmission) No more exchanges. On Mon, 12 Oct 2015 20:50:46 -0700 $Bill <dbec...@gmail.com> wrote: > This failed twice to post - emailing it. > > On 10/12/2015 09:58, David Emanuel da Costa Santiago wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA256 > > > > > > Hello all! > > > > I'm creating some sockets to a remote server and from time to time, > > the sockets get "frozen". > > > > I'm creating the socket as: > > > > $socket = IO::Socket::INET->new ( > > PeerAddr => $server, > > PeerPort => $port, > > Blocking => 1, > > Proto => 'tcp', > > Timeout => 20, #connection > > timeout ) or die "Error: Failed to > > connect : $!\n"; > > > > > > So far so good, but when i try to make a first read, the read hangs > > (always on the first read - If the first read is successfull all the > > other reads will succeed). No error whatsoever (the connection > > doesn't even drop!). > > > > I'm reading the socket as: > > > > sub _read_from_socket{ > > my ($socket) = @_; > > > > my ($output, $buffer) = ('', ''); > > while(1){ > > my $status = $socket->read($buffer, 1); > > die "Error: $!" if(!defined $status); > > $output .= $buffer; > > last if $output =~ /\r\n$|^\z/; > > } > > > > return $output; > > } > > > > > > The same happens even with a sysread (both on windows and linux > > platforms). This hanging doesn't happen everytime, it's like 1 in 6 > > tries. > > > > If i check with netstat i see the connection with state ESTABLISHED. > > > > Do you guys know what's going on? > > No, but you should be able to avoid the condition by: > 1) Use non-blocking IO on your new; or > 2) Use IO::Select can_read to test for data prior to reading; or > 3) Use an ioctl to test for data or get size of data in input Q > (FIONREAD); or 4) Use ioctl to reset blocking (FIONBIO) on socket. > > I usually use 2) to do my socket IO. > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/