🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TIdTCPServer Command Handler

#4755
From: Remy Lebeau (TeamB)
Date: Wed, 29 Dec 2004 20:05
31 lines
2507 bytes
"Ronny" <potapenko@check.com> wrote in message
news:41d307a3$1@newsgroups.borland.com...

> In the command handler for the LOGIN command,

I would suggest the OnConnect event instead.

> client * newClient = new client(ASender->Thread, login)

Is the client class derived from TObject?  If not, then you need an
OnDisconnect handler in order to free the instance properly.

> This stuff seems to cause some AV when the client disconnect.

You did not show your disconnect code.  My guess is that your client class
is not derived from TObject, and you did not provide an OnDisconnect event
handler, so the TIdPeerThread tried to free the object assigned to the Data
property and thus produced an AV.  The object assigned to the Data property
is owned by the TIdPeerThread.  When the thread is freed, the Data object is
freed as well.  If the object derives from TObject then this works fine. But
if it is not derived from TObject then TIdPeerThread has no way of freeing
it safely so you must free it your manually via the OnDisconnect event.

The alternative is to derive your client class from TIdPeerThread itself,
and set the server's ThreadClass property accordingly.  Then you do not need
to use the Data property at all, and you can cast the Thread property of
each TIdCommand to your derived class directly.


Gambit
Technical Details
Message-ID: <41d30da2@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!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41d2f642$1@newsgroups.borland.com> <41d2ff3d$1@newsgroups.borland.com> <41d3044e$1@newsgroups.borland.com> <41d307a3$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,d17d5067aebc2759
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: <41d2f642$1@newsgroups.borland.com> <41d2ff3d$1@newsgroups.borland.com> <41d3044e$1@newsgroups.borland.com> <41d307a3$1@newsgroups.borland.com>
Subject: Re: TIdTCPServer Command Handler
Date: Wed, 29 Dec 2004 12:05:04 -0800
Lines: 33
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: <41d30da2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1104350626 68.69.17.41 (29 Dec 2004 12:03:46 -0800)
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!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail