Hi All,
I hope to get some advice, currently i have already done the whole system to connect to the a messaging server using telnet. One of my function here is using the socket connect to telnet to the messaging server to get the whitepages detail of the user. Below is the function where i use to capture the result after i have issue the command.
sub SOCKETread{
my $s = $_[0];
my $buffer = "";
my ($ready, $fdmask, $nfound);
do{
$numBytes = sysread($s, $buf, 256);
$buffer .= $buf;
# loop til we have a complete response
if (($buf =~ /^OK/im) || ($buf =~ /^Error/im) || ($buf =~ /<*>
+/)){
$numBytes=0;
}
} while ($numBytes);
return $buffer;
}
Actually this function i found out that, it has a small bug, which coz my client system sometime stop in the middle of no where, and the webpage also time out. Coz it take until the telnet session close only exit this function for the next task.
First the bug is in the IF statement above. This is because, the whitepage content huge data, and the $buf each time only capture 256 bytes, unstablely maybe less. The problem occur when the $buf get from the sysread is ended with "...O" not "...OK". And it loop again coz the telnet still return something, the next loop which capture in the $buf only the "K", so it would not jump out from the do..while statement becoz it doesn't meet the condition.
Finally it stuck at the sysread because it still think that there might be something to come out but maybe slow, but the data is already finish display.
What should i do to overcome this problem, actually it is easy to change the condition, in deep of $buf to $buffer. But if this is a huge data, consider about 500 user, after joining each time make a check to it will it slow down the performance. What is the best way that i can do.
Thank you
Update: added <code> tags. larsen