 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
AntonE Guest
|
Posted: Sat May 19, 2007 1:05 am Post subject: Cleanup after disconnect |
|
|
In my (Indy10) TCPserver, I have code in OnConnect:
AContext.Connection.IOHandler.WriteLn('TrueCalendar3 server ready...');
AContext.Connection.IOHandler.WriteLn('Version 1');
AContext.Data := TUserData.Create;
TUserData(AContext.Data).PeerIP
:=AContext.Connection.Socket.Binding.PeerIP;
TUserData(AContext.Data).HostName
:=GStack.HostByAddress(TUserData(AContext.Data).PeerIP);
TUserData(AContext.Data).Connected :=Now;
TUserData(AContext.Data).LastAction:=Now;
1)Now if he connection closes by client sending disconnect, will the
TUserData be freed automatically.
2)If so, then if the user disconnects by some unforseen method (network
failure), would it also be freed automatically?
I just do not want memory leaks to be present.
Thanks
AntonE |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat May 19, 2007 2:09 am Post subject: Re: Cleanup after disconnect |
|
|
"AntonE" <antone (AT) true (DOT) co.za> wrote in message
news:464e078a (AT) newsgroups (DOT) borland.com...
| Quote: | if he connection closes by client sending disconnect,
will the TUserData be freed automatically.
if the user disconnects by some unforseen method
(network failure), would it also be freed automatically?
|
TIdContext owns the Data member. TIdContext's destructor calls Free()
on it. There is no guarantee that the TIdContext will be freed right
away, though, so I would not suggest relying on that automatic
cleanup. You are allocating the TUserData in the OnConnect event, so
you should free it yourself in the OnDisconnect event and set the Data
property to nil, ie:.
AContext.Data.Free;
AContext.Data := nil;
Gambit |
|
| Back to top |
|
 |
AntonE Guest
|
Posted: Sat May 19, 2007 3:03 am Post subject: Re: Cleanup after disconnect |
|
|
Thanks for the response.
| Quote: | you should free it yourself in the OnDisconnect event and set the Data
property to nil, ie:.
AContext.Data.Free;
AContext.Data := nil;
|
I take it then the OnDisconnect gets called even in an unforseen
(ungracefull? ) disconnect? |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat May 19, 2007 3:49 am Post subject: Re: Cleanup after disconnect |
|
|
"AntonE" <antone (AT) true (DOT) co.za> wrote in message
news:464e22c8 (AT) newsgroups (DOT) borland.com...
| Quote: | I take it then the OnDisconnect gets called even in
an unforseen (ungracefull? ) disconnect?
|
Eventually, yes. It may take a long time for the OS to detect the
ungraceful loss and invalidate the socket, though. You should
implement your own timeout code so that you can close the connection
faster.
Gambit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|