Article View: news.software.nntp
Article #55800Re: Forecasting the posting's size
From: Joshua
Date: Sun, 30 Dec 2001 23:53
Date: Sun, 30 Dec 2001 23:53
81 lines
3901 bytes
3901 bytes
"Curt Welch" <curt@kcwc.com> wrote in message
news:20011230161737.549$XI@newsreader.com...
> Nobody said writing a server would be easy. :)
Dear Curt,I never say it's easy,I just have to do. I have it started. With
your help,the work gets on favorably. I know I still need your help. I don't
care any word,I just thanks for any reply.
Here comes the piece of code to handle the posting,anything I have lost?
//-------------------------------------------------------
int CBasicClient::receive_article(char *strBuf,int len)
{
char *pInChar;
int recved_len;
unsigned flag=0;
char strStopper[]="\x0d\x0a.\x0d\x0a";
do
{
for(pInChar=strBuf;pInChar<strBuf+len-1;pInChar++)
{
// Read input stream until last char of strStopper matches
recved_len=RecvRaw(pInChar,1,0);
if(0==recved_len)
{
pInChar-- ;
break ;
}
if( *pInChar == strStopper[5-1] && pInChar - strBuf + 1 >=5)
{
// Assume match until one of the stopper chars mismatches
int bMatch = TRUE ;
for( int pos = 5 - 1; pos > 0 && bMatch; pos-- )
if( *( pInChar - 5 + pos ) != strStopper[ pos - 1 ] )
bMatch = FALSE ;
if( bMatch )
break ;
}
}
if (pInChar<strBuf+len-1) //posting is not too large reachs limit,return
normal code
break;
memmove(strBuf,pInChar-5-1,5-1); //posting is over large,reset Buffer,read
the other stream,untill CRLF.CRLF,but return over-large sign back
pInChar=strBuf+5-1;
flag++;
}while(true);
if (0<flag)
return -1; //overflow
*(pInChar+1-5)='\0'; //cut off the ending CRLF.CRLF
return pInChar-strBuf+1-5;
}
///////////////////////////////////////////////////
1.strBuf is the Buffer memory for cacheing the inputing posting. I have
allocate a max size of memory equals the posting upper limit such as
512*1024,using the following code:
char *strBuf=new char[max_posting_size];
2.I If the inputing stream reachs the limit,pInChar will approach the end of
the strBuf. After exits from for{ ... ...}segment,I know if the posting is
too big. If this happens, I (1) keep the last 4 received bytes(maybe they
happen are "CRLF.CR"),(2)reset the point to the beginning of the
strBuf(regarded the kept 4 bytes),(3)go back to read the other data in the
input stream and save them in the same strBuf,once by once,till "CRLF.CRLF"
is got. If the posting is too large,the input data will be trash,upon that I
can use the same buffer again and again. Once it overflow,I dare overlay.
At the end of the function,I return a value for telling what's happened.
This works looks correct. But I find it's obviously slower than either INN
or Dnews. I don't know how they act here. Any advice about it will be very
appreciated.
Technical Details
Message-ID:
<a0o95h$or9$1@mail.cn99.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.cn99.com!not-for-mailReferences:
<a0mi6f$qqr$1@mail.cn99.com> <20011230161737.549$XI@newsreader.com>Show Full Headers
Complete Article Headers
Message-ID: <a0o95h$or9$1@mail.cn99.com> Subject: Re: Forecasting the posting's size Date: Mon, 31 Dec 2001 07:53:06 +0800 From: "Joshua" <JoshuaIIII@hotmail.com> References: <a0mi6f$qqr$1@mail.cn99.com> <20011230161737.549$XI@newsreader.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.cn99.com!not-for-mail Newsgroups: news.software.nntp Organization: Bentium Ltd. (CN99) Lines: 80 NNTP-Posting-Host: 61.156.65.108 X-Trace: mail.cn99.com 1009756146 25449 61.156.65.108 (30 Dec 2001 23:49:06 GMT) X-Complaints-To: usenet@news.cn99.com NNTP-Posting-Date: Sun, 30 Dec 2001 23:49:06 +0000 (UTC) X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200