M
Matta
Hi,
I'm writing an NNTP based program that downloads articles from Usenet.
I've run into a weird problem. It seems as if there is a bug somewhere
that causes certain articles to download incorrectly (just by a byte or
two). It happens to the same articles and about 1 out of 5 have issues. So
everything seems to work ok, but somewhere something causes this weird
behavior.
The code that should work but doesn't (sometimes) downloads an article and
returns it.
Any help would be appreciated.
Matta
- - - - -
string NNTP::net_recv()
{
int numbytes;
string buffer;
char buf[MAXDATASIZE];
numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0);
if (numbytes < 1) {
return "";
}
buf[numbytes] = '\0';
buffer = buf;
return buffer;
}
extern "C" string NNTP::get_article(string msgid)
{
string rdata, sendstr, tmp;
string::size_type pos;
sendstr = "ARTICLE ";
sendstr += msgid;
sendstr += "\r\n";
net_send(sendstr);
rdata = "";
do {
rdata += net_recv();
} while (rdata.substr(rdata.length()-5, 5) != "\r\n.\r\n");
rdata = rdata.substr(0, rdata.length() - 3);
pos = rdata.find("\r\n\r\n", 0);
rdata = rdata.substr(pos + 4, rdata.length() - (pos + 4));
if (rdata.substr(0, 2) == "..") {
rdata.erase(0, 1);
}
pos = 0;
while ((pos = rdata.find("\r\n..", pos)) != string::npos) {
rdata.erase(pos + 2, 1);
}
return rdata;
}
I'm writing an NNTP based program that downloads articles from Usenet.
I've run into a weird problem. It seems as if there is a bug somewhere
that causes certain articles to download incorrectly (just by a byte or
two). It happens to the same articles and about 1 out of 5 have issues. So
everything seems to work ok, but somewhere something causes this weird
behavior.
The code that should work but doesn't (sometimes) downloads an article and
returns it.
Any help would be appreciated.
Matta
- - - - -
string NNTP::net_recv()
{
int numbytes;
string buffer;
char buf[MAXDATASIZE];
numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0);
if (numbytes < 1) {
return "";
}
buf[numbytes] = '\0';
buffer = buf;
return buffer;
}
extern "C" string NNTP::get_article(string msgid)
{
string rdata, sendstr, tmp;
string::size_type pos;
sendstr = "ARTICLE ";
sendstr += msgid;
sendstr += "\r\n";
net_send(sendstr);
rdata = "";
do {
rdata += net_recv();
} while (rdata.substr(rdata.length()-5, 5) != "\r\n.\r\n");
rdata = rdata.substr(0, rdata.length() - 3);
pos = rdata.find("\r\n\r\n", 0);
rdata = rdata.substr(pos + 4, rdata.length() - (pos + 4));
if (rdata.substr(0, 2) == "..") {
rdata.erase(0, 1);
}
pos = 0;
while ((pos = rdata.find("\r\n..", pos)) != string::npos) {
rdata.erase(pos + 2, 1);
}
return rdata;
}