🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4323

Re: TCustomWinSocket Lock()!!!

#4323
From: qyte
Date: Sun, 06 Mar 2005 22:48
95 lines
4495 bytes
> That sounds more like a bug in your own code and not in the socket
> themselves.  Please show your actual code that is not doing what it is
> supposed to be doing.
> 
> 
> Gambit


void   fol_dckl(int typ)
{
         Form3->Button1->Enabled=false;
         Form3->Cursor=crAppStart;
         if(typ==1)
                 NAME=Form3->Edit1->Text+"\\"+NAME;
         Form3->Edit1->Text=NAME;
         strcpy(spath,NAME.c_str());
         Form3->ListView->Items->Clear();
         int g=-2;
         while(Form1->sock[1]->SendBuf(&g,sizeof(int))<0);
         g=strlen(spath);
         g++;
         while(Form1->sock[1]->SendBuf(&g,sizeof(int))<0);
         while(Form1->sock[1]->SendBuf(spath,g)<0);
}

that function is called to send a folder name to the other side.
in the other side sock[2] receives it and calls the following function
to send back the folder data so it can be viewed.

void __fastcall TForm1::Send_fdata(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(Form1->sock[1]->SendBuf(&w,sizeof(int))<0);
         while(Form1->sock[1]->SendBuf(&sz,sizeof(int))<0);
         while(sz>count)
         {
                 if(Form1->sock[1]->SendBuf(fData,count)<0)
                         continue;
                 sz-=count;
                 fData+=count;
         }
         while(Form1->sock[1]->SendBuf(fData,sz)<0);
}

the code above works pretty good. The problem occurs when both users on 
each side click on a folder (any folder). Of course the more files the 
folder contains the bigger the possibility of an error to occur. I 
believe that what happens is that among the send_fdata function the 
fol_dblk can be called and try to send data since the folder data is not 
sent immediately in one sendbuf call there can be confusion when amongst 
these calls other calls take place. that's why i wanted to know if the 
socket was idle. because i wasn't dealing with one sendbuf call but with 
many. Does anyone know for sure if i add a bool variable that will be 
true before the calls and false soon after would do? of course that 
would be included in one function and the other just before the start of 
the sendbuf calls could do a while(var);.

Thanks anyway
Technical Details
Message-ID: <422b88c4@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.wiretrip.org!border2.nntp.ams.giganews.com!nntp.giganews.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
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>

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 00:48:36 +0200
From: qyte <gyte@vivodinet.gr>
User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913)
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>
In-Reply-To: <422b6fb5$1@newsgroups.borland.com>
Content-Type: text/plain; charset=windows-1253; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 83.171.210.195
Message-ID: <422b88c4@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1110149316 83.171.210.195 (6 Mar 2005 14:48:36 -0800)
Lines: 95
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.wiretrip.org!border2.nntp.ams.giganews.com!nntp.giganews.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail