🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: 'Out of memory' exception for a IdTCPServer

#5497
From: Drew
Date: Thu, 12 Aug 2004 21:21
206 lines
7923 bytes
The situation is as follows:

There are two applications (currently running on the same PC).  One
application sends values across a TCP link to the other application that
writes the values into the database.  They use a IdTCPClient/IdTCPServer
pair to form the TCP link.

On the server side, the following code is used to set up the IdTCPServer:

    RtrServer->OnDisconnect = RtrServerDisconnect;
    RtrServer->OnException  = RtrServerException;
    RtrServer->OnListenException = RtrServerListenException;
    RtrServer->Active = true;

    RtrServer->CommandHandlersEnabled = true;

    RtrServer->CommandHandlers->Add();
    RtrServer->CommandHandlers->Items[0]->Command = readRtrParams;
    RtrServer->CommandHandlers->Items[0]->OnCommand =
RtrServerReadRtrParams;

    RtrServer->CommandHandlers->Add();
    RtrServer->CommandHandlers->Items[1]->Command = read10Hilltops;
    RtrServer->CommandHandlers->Items[1]->OnCommand =
RtrServerReadMultipleHilltops;

    RtrServer->CommandHandlers->Add();
    RtrServer->CommandHandlers->Items[2]->Command = updateHilltopInfo;
    RtrServer->CommandHandlers->Items[2]->OnCommand =
RtrServerUpdateHilltops;

The exception handlers are as follows:

//--------------------------------------------------------------------------
-
void __fastcall RTRSvrThread::RtrServerDisconnect(TIdPeerThread *AThread)
{
    Log(0, "Rtr Server disconnected");
}
//--------------------------------------------------------------------------
-
void __fastcall RTRSvrThread::RtrServerException(TIdPeerThread *AThread,
Exception *e)
{
    sprintf(msg, "Rtr Server exception: %s", e->Message);
    Log(0, msg);
}
//--------------------------------------------------------------------------
-
void __fastcall RTRSvrThread::RtrServerListenException(TIdListenerThread
*Athread, Exception *e)
{
    Log(0, "Rtr Server listen exception");
}

The error log shows the following:

    19:59:43.56: Rtr Server exception: Out of memory
    19:59:43.56: Rtr server disconnected

The client has just sent a message of type 'updateHilltopInfo', which will
trigger the command handler 'RtrServerUpdateHilltops'.  The code on the
client side to send the message across the TCP link is:

  // Send the data obtained from the hilltop back to DBM to update the
database

  AnsiString msgType = updateHilltopInfo;

  Log(2, "Sending updateHilltopInfo message to DBM");

 if (DbmClient->Connected())
 {
       try
       {
               DbmClient->WriteLn(msgType);

               try
              {
                      msgType = DbmClient->ReadLn();

                      if (msgType == ACK)
                     {
                                Log(2, "Read ACK from DBM");
                               char* sendBuffer;

                               sendBuffer = new char[sizeof(SiteData_t)];

                               memcpy(sendBuffer, site, sizeof(SiteData_t));

                               Log(2, "Sending info buffer to DBM");
                               DbmClient->WriteBuffer(sendBuffer,
sizeof(SiteData_t));

                               delete[] sendBuffer;

                               try
                               {
                                       msgType = DbmClient->ReadLn();

                                       if (msgType == ACK)
                                       {
                                               Log(2, "Read ACK again from
DBM");
                                               {
                                                     sprintf(msg, "About to
delete site ID %d", site->siteID);
                                                     Log(2, msg);
                                               }
                                               if (site)
                                               {
                                                   delete site;
                                               }
                                               DecSiteCount();
                                        }
                                        msgSent = true;

                               }
                               catch (Exception &e)
                               {
                                      {
                                             sprintf(msg, "Read of second
ACK failed: exception = %s", e.Message);
                                              Log(0, msg);
                                       }
                               }
                     }
                     else
                     {
                             {
                                    sprintf(msg, "Read non-ACK reply from
DBM - msg = %s", msgType);
                                    Log(0, msg);
                             }
                    }
             }
             catch (Exception &e)
             {
                    Log(0, "Read of ACK from DBM failed");
                   {
                           sprintf(msg, "Exception generated = %s",
e.Message);
                           Log(0, msg);
                   }
             }
      }
      catch (Exception &e)
     {
            {
                  sprintf(msg, "Write of updateHilltopInfo message to DBM
failed: exception = %s", e.Message);
                  Log(0, msg);
            }
           msgSent = true;
    }

On the client side, the error log shows:

    19:59:43.56: Sending updateHilltopInfo message to DBM
    19:59:43.56: Read of ACK from DBM failed
    19:59:43.56: Exception gnerated = Connection Closed Gracefully.


This occrs after the system has been running for several hours (around 6 on
the last attempt).

Other applications on the same machine are using a similar mechanism to send
data to the server task, and these continue unaffected.

Can you see anything that I'm doing wrong?

Thanks

Andrew

"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:411ba247$1@newsgroups.borland.com...
>
> "Drew" <aemsley@brightwell.org.uk> wrote in message
> news:411b903e@newsgroups.borland.com...
>
> > Can anyone tell me what an 'Out of memory' exception
> > for a IdTCPServer means?
>
> Exactly what it says - it tried to allocate a piece of memory and could
not
> because the system did not have available memory for it.
>
> > The system is not low on memory
>
> There are many different types of memory and resources available for
> allocation.  Any of them could be low.  And such an error is not specific
to
> Indy anyway, it is from the VCL itself.
>
> > Is there anything that I can do once ths has occurred - for instance,
> would
> > simply reconnecting the TCP connection be OK
>
> It depends on what exactly is failing to begin with.  Please provide more
> details.  Where does the exception occur?  Under what circumstances?
>
>
> Gambit
>
>
Technical Details
Message-ID: <411bdf12$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <411b903e@newsgroups.borland.com> <411ba247$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,56db4bd962ab0eb3
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Drew" <aemsley@brightwell.org.uk>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <411b903e@newsgroups.borland.com> <411ba247$1@newsgroups.borland.com>
Subject: Re: 'Out of memory' exception for a IdTCPServer
Date: Thu, 12 Aug 2004 22:21:41 +0100
Lines: 208
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 81.137.221.84
Message-ID: <411bdf12$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1092345618 81.137.221.84 (12 Aug 2004 14:20:18 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail