CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
problem with a blocking recv function over socket

 



tnaveenkumar
New User

May 11, 2009, 6:29 AM

Post #1 of 1 (222 views)
problem with a blocking recv function over socket Can't Post

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.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives