Article View: borland.public.cppbuilder.internet.socket
Article #4225Re: TCustomWinSocket Lock()!!!
From: Hans Galema
Date: Mon, 07 Mar 2005 08:20
Date: Mon, 07 Mar 2005 08:20
107 lines
4021 bytes
4021 bytes
qyte wrote:
> void __fastcall TForm1::Send_fdata(char *ph)
>
> the code above works pretty good.
But that is not good enough. Reason: bad checking for
the return value of SendBuf. If you ask SendBuf to send
40.000 bytes then it may only send 8192 so it returns 8192.
You have to check that.
Further Send_fdata is a memberfunction of Form1
so you do not need to specify
Form1->sock[1]-> ... every time.
sock[1]->
would do. But then the use of sock[1] is not
very good too. Better give your function an extra parameter:
void __fastcall TForm1::Send_fdata(TCustomWinSocket *Socket, char *ph)
{
TSearchRec sr;
int t;
t=FindFirst(AnsiString(ph)+"\\*.*",faDirectory,sr);
if(sr.Name.SubString(1,1)==".")
{
FindNext(sr);
t=FindNext(sr);
}
ffiles="";
FDATA="";
int file=0;
int w=-1;
while(t==0)
{
if(sr.Name=="AUTOEXEC.BAT" || sr.Name=="CONFIG.SYS")
{
t=FindNext(sr);
continue;
}
if((sr.Attr & faDirectory)==0)
{
file++;
ffiles+=sr.Name+"*0"+AnsiString(sr.Size)+"?";
}
else
{
FDATA+=sr.Name+"*1";
}
t=FindNext(sr);
}
FindClose(sr);
if(file>0)
FDATA+=ffiles;
FDATA+="\0";
fData=FDATA.c_str();
int sz=FDATA.Length();
sz++;
while(Socket->SendBuf(&w,sizeof(int))<0);
Now you asked to send 4 bytes. Now if only three were
sent ?
while(Socket->SendBuf(&sz,sizeof(int))<0);
Ditto.
while(sz>count)
Where is count initialized ? Why is this not a local variable
that you initialised here ?
Are you using the same variable for receiving?
{
if(Socket->SendBuf(fData,count)<0)
continue;
What was the value of count ? You should have put there sz.
And you assumed that all count bytes were sent.
Better:
while ( sz )
{
int nsended = Socket->SendBuf(fData,sz);
if ( nsended < 0 )
{
// decide what you do
}
else
{
sz-=nsended;
fData+=nsended;
}
}
while(Socket->SendBuf(fData,sz)<0);
Ditto.
}
Hans.
Technical Details
Message-ID:
<422c0f20$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4228f8c1$1@newsgroups.borland.com> <42290e8b$1@newsgroups.borland.com> <42297c51$1@newsgroups.borland.com> <42298b47$1@newsgroups.borland.com> <42299308@newsgroups.borland.com> <422b6fb5$1@newsgroups.borland.com> <422b88c4@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,9c76e7cb52ebcfdd X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 07 Mar 2005 09:20:06 +0100 From: Hans Galema <notused@notused.nl> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: TCustomWinSocket Lock()!!! References: <4228f8c1$1@newsgroups.borland.com> <42290e8b$1@newsgroups.borland.com> <42297c51$1@newsgroups.borland.com> <42298b47$1@newsgroups.borland.com> <42299308@newsgroups.borland.com> <422b6fb5$1@newsgroups.borland.com> <422b88c4@newsgroups.borland.com> In-Reply-To: <422b88c4@newsgroups.borland.com> Content-Type: text/plain; charset=windows-1253; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 129.125.201.248 Message-ID: <422c0f20$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1110183712 129.125.201.248 (7 Mar 2005 00:21:52 -0800) Lines: 107 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail