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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.