🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: threadblocking server connection handling

#4150
From: havl
Date: Thu, 24 Mar 2005 15:20
77 lines
3496 bytes
by length i ment the size of data received by read operation
...which was caused by waitfordata returning true

a single clientthread goes like this
i am trying to use other thread to control many of theese by accesing their 
variables and buffers once in every 50ms

ClientExecute()
{
TWinSocketStream* str=new TWinSocketStream(ClientSocket,timeout); //timeout 
for read/write 5000
int u; //number of bytes sent/received by last operation
while(n)        //if false thread terminates and that tells the control 
thread to handle it
{
        if(!f)    //do nothing unless control thread handles new, complete 
data packet in read buffer
        {


                if(str->WaitForData(0))
                {
                        r=true;       //starting reading
                }
                else
                {
                        r=false;   //do not read if nothing's incoming
                }

                if(r)
                {
                        u=str->Read(rbuf,hsize-ph); //actual reading
                                                                    //read 
in hsize byte packets, ph controls position
                        if(u==0)
                        {
                                n=false;        //client disconnected ?
                        }
                        else
                        {
                                ph+=u;
                                if(ph==hsize)   //packet completed
                                {
                                        ph=0;
                                        r=false;
                                        f=true;    //set fresh data flag for 
control thread
                                }
                        }
                }

                if(w&&!r)      //control thread can update write buffer and 
bool w var to send data
                {
                        u=str->Write(wbuf,sw-pw);   //send up to sw bytes of 
buffer, pw controls position
                        pw+=u;
                        if(pw==sw)
                        {
                                pw=0;
                                w=false; //sent all
                        }
                }


        }    //if(!f)
}    //while(n)

delete str;
ClientSocket->Close();
}

buffers are about 100 bytes
exceptions appear when client disconnects during sending data
they show that adress that i'am trying to send to is no longer availble and 
point to str->Write() command
it behaves as if disconnection wasn't triggered 
Technical Details
Message-ID: <4242da71@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4242c0bb@newsgroups.borland.com> <4242c5a1$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,541706e3e4df9e6e
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "havl" <havl83@wp.pl>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <4242c0bb@newsgroups.borland.com> <4242c5a1$1@newsgroups.borland.com>
Subject: Re: threadblocking server connection handling
Date: Thu, 24 Mar 2005 16:20:21 +0100
Lines: 79
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 81.219.101.38
Message-ID: <4242da71@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1111677553 81.219.101.38 (24 Mar 2005 07:19:13 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail