Skip to Content.
Sympa Menu

freetds - Re: [freetds] cancel and timeout

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT schemamania.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] cancel and timeout
  • Date: Thu, 20 Jan 2005 22:36:44 -0500

On Thu, 20 Jan 2005 17:11:12 -0000, "Thompson, Bill D (London)"
<bill_d_thompson AT ml.com> wrote:
> > Timeout
> > -------
> > Now if a timeout (now query_timeout) a query_timeout_func it's called.
> I
> > removed chkintr and hndlintr (one function it's sufficient).
> > query_start_time it's use for global time counting. I don't know if
> > query timeout on dblib works as expected. Perhaps even SQLFetch or
> > similar need setting timeout.
>
> I think there are two functions because this then mirrors the dblibrary
> interrupt handlers.

Thanks for tackling this, Freddy.

I think Bill means:

void dbsetinterrupt(dbproc, chkintr, hndlintr)

DBPROCESS *dbproc;
int (*chkintr)();
int (*hndlintr)();

http://sybooks.sybase.com/onlinebooks/group-cnarc/cng1000e/dblib/@Generic__BookTextView/34848;pt=34848;uf=0#X


Note the comment:

"DB-Library does non-blocking reads from the server. While waiting for a
read from the server, it will call the chkintr() function to see if an
interrupt is pending. If chkintr() returns TRUE and a handler has been
installed as the hndlintr() for dbsetinterrupt, hndlintr() will be
called."

That's not how dblib_query_timeout() is currently coded. chkintr should
be called periodically from within src/tds/net.c::goodread() until either:

1. the server sends data, or
2. the query_timeout expires.

goodread() calls hndlintr after the timeout. It should call it while
counting down to the timeout. How often? The docs don't say. They say
they (Sybase) do non-blocking I/O, implying a busy wait. I think it would
be OK to call select(2) with a timeout of, say, 100 ms (blocking), then
call hndlintr, then busyfunc, then deduct 100 ms from query_timeout, and
call select(2) again. Something like:

for (ti = selecttimeout;
retcode = select(tds->s + 1, &fds, NULL, NULL, ti);
ti.tv_usec -= 100)
{
if (retcode < 0) {
/* error */
}
if (retcode > 0) {
break; /* data ready: read */
}
assert(retcode == 0); /* partial timeout */
if (ti.tv_usec < 0) {
ti.tv_sec--;
ti.tv_usec += 1000;
}

if (ti.tv_sec < 0) break; /* really timed out */

if ((*tds->chkintr)())
(*tds->hndlintr());
if (tds->busyfunc)
(*tds->busyfunc)();
}

len = READSOCKET(tds->s, buf + got, buflen);

if (tds->idlefunc)
(*tds->idlefunc)();


These may also be interesting:

dbsetidle:
http://sybooks.sybase.com/onlinebooks/group-cnarc/cng1000e/dblib/@Generic__BookTextView/34650;pt=3564

"idlefunc() will be automatically called whenever DB-Library has finished
reading output from the server."

dbsetbusy:
http://sybooks.sybase.com/onlinebooks/group-cnarc/cng1000e/dblib/@Generic__BookTextView/34263;pt=34263;uf=0#X

"automatically called whenever DB-Library is reading or waiting to read
output from the server."

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page