 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Martin James Guest
|
Posted: Wed May 16, 2007 7:22 pm Post subject: Indy and/or ICS - connection object lifetime |
|
|
It seems that both of these component sets have servers that auto-free their
connection socket-objects, (whatever they are called in each set), upon
client disconnect. I don't want this to happen. I want to keep the
connection-objects after the client connection drops. I want to free them
myself after a couple minutes, (I will put them in a timeout list).
Why? So that other threads/whatever that intend to write through these
connection-objects, or queue objects to them, can detect that the connection
has gone and not try to do things they were going to do that will now fail.
I would rather not use an AV or Windows socket error as a method of
detection for this - I would like to have a little CS-protected state inside
the connection-object that can be referred to.
How can I do this with Indy, (9), or ICS?
Rgds,
Martin |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed May 16, 2007 10:00 pm Post subject: Re: Indy and/or ICS - connection object lifetime |
|
|
"Martin James" <nospam (AT) tuthill (DOT) com> wrote in message
news:464b13af (AT) newsgroups (DOT) borland.com...
| Quote: | It seems that both of these component sets have servers that
auto-free
their connection socket-objects, (whatever they are called in each
set),
upon client disconnect.
|
As they should be, because they can't be reused anymore after a
disconnect.
| Quote: | I don't want this to happen.
|
Then you will have to write your own server code from scratch.
| Quote: | I want to keep the connection-objects after the client connection
drops. I want to free them myself after a couple minutes, (I will
put
them in a timeout list).
Why? So that other threads/whatever that intend to write through
these connection-objects, or queue objects to them, can detect that
the connection has gone and not try to do things they were going to
do that will now fail.
|
They are going to fail anyway. The sockets are invalid once they have
been disconnected. They will raise errors of their own when anything
tries to access them afterwards. So you are better off just coding
your operations to handle errors of any kind, whether that be socket
errors or invalid pointer errors or whatever.
| Quote: | I would rather not use an AV or Windows socket error as a
method of detection for this
|
That is what you should be doing, though. That is the only way your
operations can detect disconnections to begin with. Even if the
sockets are not freed right away, you still have to pay attention to
the error codes that are reported by the socket functions in order to
know whether the reads/writes succeeded or failed.
| Quote: | I would like to have a little CS-protected state inside the
connection-object that can be referred to.
|
Then I suggest you create your own class that holds a connection as a
member, and then pass that class around everywhere instead of the
connection by itself. Your class can contain whatever state
information you want, even provide CS-protected access to the
connection itself. When a client disconnects, you can remove the
connection from the class without freeing the class itself right away.
Gambit |
|
| Back to top |
|
 |
Martin James Guest
|
Posted: Thu May 17, 2007 1:42 pm Post subject: Re: Indy and/or ICS - connection object lifetime |
|
|
| Quote: |
As they should be, because they can't be reused anymore after a
disconnect.
|
What happens if the connection object is freed and then reallocated in
another connect? If the same memory area happens to be used, a write
through the connection object will succeed, resulting in data being sent to
the wrong client.
Rgds,
Martin |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu May 17, 2007 2:02 pm Post subject: Re: Indy and/or ICS - connection object lifetime |
|
|
"Martin James" <nospam (AT) tuthill (DOT) com> wrote in message
news:464c1583$1 (AT) newsgroups (DOT) borland.com...
| Quote: | What happens if the connection object is freed and then
reallocated in another connect?
|
It is a complete fresh connection that is not related to the previous
connection.
| Quote: | If the same memory area happens to be used, a write through
the connection object will succeed
|
Even though the TIdTCPConnection object may happen to occupy portions
of the same memory, it would be extremely rare for it to occupy the
EXACT same memory beginning at the EXACT same starting address.
In any case, it is your own responsibility to clean up all of your
references to a connection when it has been disconnected. I already
gave you one suggestion for that.
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
|
|