Skip to Content.
Sympa Menu

freetds - Re: [freetds] Timeout for reading from the server doesn't work.

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Timeout for reading from the server doesn't work.
  • Date: Thu, 24 Nov 2005 10:12:59 +0100

>
> Dear list,
>
> I use this great library (libtds) to communicate with MSSQL
> server on an
> embedded system. It's rather important that this system never stops
> sending data for a longer period of time. But as far as I
> could observe
> this occurs every time the server becomes unreachable. In both the
> stable release and the CVS version a timeout can be set for this case,
> but in the stable version this triggers an assertion and in the CVS
> version as far as I understand the code it leads to an infinite loop.
> For the latter case there is a rather simple fix which makes the
> goodread function abort instead of waiting forever. I only insert data
> into the database but this has worked reliably now for the
> last 4 days.
>
> best regards
> Omar Siam
>

Opss... please ignore my previous mail. len == 0 means select timeout or
connection close (recv returned 0) so IMO the best way is to detect
connection close in side if ((len = select... and close connection
correctly.

Patch follows (already committed)

diff -u -1 -0 -r1.34 net.c
--- src/tds/net.c 7 Oct 2005 15:07:27 -0000 1.34
+++ src/tds/net.c 24 Nov 2005 09:08:16 -0000
@@ -310,20 +310,25 @@
tv.tv_sec = timeout;

if ((len = select(tds->s + 1, &rfds, NULL, NULL, timeout
> 0 ? &tv : NULL)) > 0) {
len = 0;
if (FD_ISSET(tds->s, &rfds)) {
#ifndef MSG_NOSIGNAL
len = READSOCKET(tds->s, buf + got,
buflen);
#else
len = recv(tds->s, buf + got, buflen,
MSG_NOSIGNAL);
#endif
+ /* detect connection close */
+ if (len == 0) {
+ tds_close_socket(tds);
+ return -1;
+ }
}
}

if (len < 0) {
switch(sock_errno) {
case TDSSOCK_EINTR:
tdsdump_log(TDS_DBG_NETWORK, "socket
read interrupted\n");
case EAGAIN:
case TDSSOCK_EINPROGRESS:
break;

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page