Subject Re: timeout a pending connection via a bad network?
Author Adam
> Thank you, however, it can only tell me the responsetime, if any. Now I
> can decide, just before starting a connection: 'Ping is taking too
long,
> better try again later'. But this can only be used to determine wether
> to start a connection or not.
>
> Suppose the network is good, I start my ACTION (connect to FB server,
> start a transaction, do something, commit or rollback, disconnect).
>
> Just before starting the ACTION, I start a timer in another thread.
>
> I keep monitoring this timerthread and some flag that indicates that
> ACTION should have been finished. At a certain time I might find:
> 'ACTION is taking too long, something obviously went wrong, something
> that apparantly does not trigger any errors or timeouts in the NOS, the
> sockets, the API, my IBObjects, my application. I want to, I even must
> abort'.

Delphi handles most messages from within the main thread. I do not
know enough about IBOs internal implementation and whether it performs
its operations inside the main thread or a separate thread, I assume
it probably goes the simple route.

>
> Same thing on explorer, mozilla or whatever browser. It can and will
> tell me if a server can be reached, it can tell me if there are errors
> in the pages etc etc.

But is the main thread doing the "reaching", or is the main thread
simply waiting a predefined number of seconds before terminating a
worker thread which hasn't responded in a timely fashion?

But it happens quite frequently that NO errors are
> triggered, that a message 'loading data from xxxx' is displayed on the
> statusbar and that some animated gif shows me the waiting state of the
> browser. But there IS a button to interrupt/abort the process! You
don't
> need taskmanager to kill the application...
>
> And that is my simple question. How to abort gracefully a bad
> connection? Can it be done?

It depends on your definition of a bad connection. If you decided that
the connection was bad because it was too slow to respond, but wasn't
so bad that the connection was dropped, then you could disconnect the
normal way, rolling back the transaction in the process.

If you mean that the connection is so poor that you are unable to
manage any comms, then you can not do a graceful disconnection.

If not gracefully, would it be possible and
> safe (and how?) to use something like IB_Connection.Forcedisconnect?
> Would it be responsive or would it be busy and trapped in its own
thread?

Unless it creates its own comms thread, then the main thread will be
tied up waiting for the response. and will have to wait until the
operation fails before processing the ForceDisconnect. A bit of irony
there I suppose, unless the connection responds, you can not cancel
it. If IBO creates a comms thread, then IBO could indeed kill that
thread if it received a ForceDisconnect etc.

Of course there is nothing stopping you from running your queries from
a separate thread and synchronising when you get the result.

Adam