🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Remy Could you have a look

#4519
From: mike
Date: Thu, 03 Feb 2005 14:41
107 lines
3135 bytes
Remy,

Could you have a look at this code sample and see if in your opinion I am 
approaching the problem correctly. If not could you point out where I am 
confused or wrong. I sure would appreciate it.

I would be doing this on a Non Blocking Socket.

Thanks very much

Mike



void __fastcall TStdPopWin::ClientSocket1Read(TObject *Sender,

TCustomWinSocket *Socket)

{

int Size, NbrBytesRead, TotalBytesToExtract, BytesToReceive, TotalBytesRead 
;

Size = 0 ;

 while ( true )

 {

              BytesToReceive = Socket->ReceiveLength() ;

              if ( BytesToReceive <= 0 )

             {

                    break ;

             }

            NbrBytesRead = Socket->ReceiveBuf( &Size, sizeof(int) ) ;

            if ( NbrBytesRead <=0 )

           {

                  break ;

           }

           TotalBytesToExtract = Size ;

           while ( Size > 0 )

          {

                     char *buffer = new char[ Size+1 ] ;

                     memset( buffer, 0x00, sizeof( buffer ) ) ;

                    TotalBytesRead = 0 ;


                   while ( true )

                  {

                               NbrBytesRead = Socket->ReceiveBuf( 
(char*)buffer,TotalBytesToExtract) ;


                               if ( NbrBytesRead > 0 )

                             {

                                    TotalBytesRead += NbrBytesRead ;

                                     if ( TotalBytesRead == Size )

                                   {

                                           break ;

                                    }

                                    TotalBytesToExtract -= TotalBytesRead ;

                           }

                  }

                  ..............Do Something with the data read from the 
Socket

                 delete[] buffer ;

                 break ;


          }

         // Loop around to see if anything else has arrived in the Socket 
Buffer


    }

}
Technical Details
Message-ID: <4200e6a4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!demon!news-lond.gip.net!news.gsl.net!gip.net!easynet-monga!easynet.net!news-out2.kabelfoon.nl!83.128.0.10.MISMATCH!newsfeed.kabelfoon.nl!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,8d9554d7f46a1c91,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "mike" <mfbrowne@earthlink.nnet>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Remy Could you have a look
Date: Thu, 3 Feb 2005 09:41:05 -0500
Lines: 109
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 68.204.189.169
Message-ID: <4200e6a4$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1107355300 68.204.189.169 (2 Feb 2005 06:41:40 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!demon!news-lond.gip.net!news.gsl.net!gip.net!easynet-monga!easynet.net!news-out2.kabelfoon.nl!83.128.0.10.MISMATCH!newsfeed.kabelfoon.nl!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail