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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.