🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: a IdTCPClient solution

#3698
From: Remy Lebeau (TeamB)
Date: Thu, 21 Jul 2005 22:23
85 lines
4045 bytes
"Roberto Zais" <rzaiss@tiscali.it> wrote in message
news:42e010be$1@newsgroups.borland.com...

> [Rarely I notice  errors, They are rare but persistent ..( Connection
> refused)

"Connection refused" means that either 1) the server is not running, or 2)
it has too many pending client requeusts and can't accept anymore until it
handles the ones that are already pending.

> TCPClient->ReadTimeout = 100;            //READ_STACK_TIMEOUT;

Why are you setting that every time the function is called?  You don't need
to.  Just set it once before calling Connect().  Or better yet, don't set it
at all.  Pass your timeout to ReadFromStack() directly instead of
IdTimeoutDefault.

>         if(TCPClient->InputBuffer->Size  == 0 )
>                 size_readable =
> TCPClient->ReadFromStack(true,IdTimeoutDefault,true);
>               else
>                 size_readable = TCPClient->InputBuffer->Size;
>         }

>        catch(Exception& e){       // Without display

Always catch exception by 'const' references:

    catch(const Exception& e){       // Without display

>           String sbuf = String(e.ClassName()) + " " + e.Message.c_str();

Don't use c_str() like that:

    String sbuf = String(e.ClassName()) + " " + e.Message;

>           if (String(e.ClassName()) == "EIdReadTimeout")
>                   return;                 // lets in waiting read loop

That is not a good way to handle exception testing.  If you want to know if
an exception is a particular class type, then you should be using
dynamic_cast instead:

    if (dynamic_cast<EIdReadTimeout*>(&e) != NULL )

Better would be to catch the specific exception type directly instead:

    catch(const EIdReadTimeout &)
    {
        return;
    }

Better would be to not throw an exception at all.  Specify False instead of
True for the ARaiseExceptionOnTimeout parameter of ReadFromStack().  That is
what the earlier code sample was doing.

>     if(ser_start <= ser_end)
>                                             // circular buffer
>          size = Min((ser_end + MAX_BUF - ser_start),size_readable);
>             else
>                                             // buffer disposto linearmente
:
>                                             // spazio libero = semplice
> differenza puntatori
>          size = Min((ser_end - ser_start),size_readable);    // al limite,
> zero

How EXACTLY are your packets actually formatted?  It doesn't look like you
are taking the advice of the earlier code sample:

    "I would strongly recommend that you prefix your packets with the actual
size of the packets.  Then you don't have to limit your buffer size during
reading, and can send small and large packets alike"

>     TCPClient->ReadBuffer(buf, size);
> // are possible any errors in this phase  ???

No, if the InputBuffer actually has the specified number of bytes available.
If it doesn't, then it has to call ReadFromStack() again (as well as
CheckForDisconnect()) to read more bytes, and that can potentially throw
exceptions.


Gambit
Technical Details
Message-ID: <42e02116@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42e010be$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,a84606e83349b98f
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <42e010be$1@newsgroups.borland.com>
Subject: Re: a IdTCPClient solution
Date: Thu, 21 Jul 2005 15:23:34 -0700
Lines: 87
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <42e02116@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1121984790 68.69.17.41 (21 Jul 2005 15:26:30 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail