i have a script used in my application to communicate with the application on a board and cater its requests over ethernet.
my script acts as client program, the link establishing code is as follows
sub tb_data_lnk_open { my ($link_add); my ($network_addr, $port_addr); my ($remote_host, $remote_port); $link_add = $_[0]; #===================================================================== +====# # The input $link_add contains the IP address and port in a single # # separated by a - # #===================================================================== +====# ($remote_host, $remote_port) = split( /-/, $link_add); #===================================================================== +====# # Create a socket. The socket is openend with TCP properties # #===================================================================== +====# socket(LINK_HNDL, PF_INET, SOCK_STREAM, getprotobyname('tcp')); #===================================================================== +====# # Remote address to connect in the network format # #===================================================================== +====# $network_addr = inet_aton($remote_host) or return 0; $port_addr = sockaddr_in($remote_port, $network_addr); #===================================================================== +====# # Connect to the server which is already listening # #===================================================================== +====# connect(LINK_HNDL, $port_addr) or return 1; return 0; }
and recieve function is as follows, which i want it to timeout after 100 seconds
sub tb_data_recv { my ($size, $data, $temp, $length_read); $size = $_[0]; $data = ""; $length_read = length($data); my $time_elapsed = 0; my $start_time = time(); #print "\nStart Time :$start_time "; my $count = 0; while($length_read < $size) { recv(LINK_HNDL, $temp, $size - length($data), $flags); $time_elapsed = time() - $start_time; #print "\n$count|Time Elapsed :$time_elapsed : $TIME_OUT : **$temp** : + **$data** \n"; if($time_elapsed > $TIME_OUT) { $data = ""; goto TEST_DOC_REP_CRASH; #return $data; } $data = $data.$temp; $length_read = length($data); $count++; } # print "\nTimeOut Not Detected"; return $data; }
but if i switch of board, where server is running, the perl script is still blocked at recv call.
can any one please tell me how to achieve that.(i have tried few things i found on internet, like setting timeout "setsockopt(LINK_HNDL, SOL_SOCKET, SO_RCVTIMEO, pack('LL', 1, 0));")
but still didn't work.
Script runs on windows machine, server/application(c code) runs on board on montavista linux.
if this is not the right place to ask, please give me pointers to where should i ask.
If anyother information is needed for understanding or solving, do tell me.
In reply to problem with a blocking recv function over socket by nav1729
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |