Error handling patch

Geoff Winkless geoff at farmline.com
Mon Jan 24 11:38:53 EST 2000


Ok, this is pretty much a hack. It's absolutely what I wanted to make my
program work, let me know if you hate it...

Usual disclaimers, I haven't really tested this yet, I'd like comments as to
what people think, especially about the DBDEAD command checking for the
status of tds_socket->s

I also haven't made any changes either to ODBC or CTLib to take into account
the changes in tds - so they would probably break.

Anyone needs any explanations, do post to the list.

Geoff


diff -b -B -c -x Mak* -x config* -r freetds/src/dblib/dblib.c
newfreetds/src/dblib/dblib.c
*** freetds/src/dblib/dblib.c Wed Dec  1 03:20:34 1999
--- newfreetds/src/dblib/dblib.c Mon Jan 24 16:28:52 2000
***************
*** 553,559 ****
     tds = dbproc->tds_socket;

     retcode = tds_process_result_tokens(tds);
!
     if (retcode == TDS_NO_MORE_RESULTS) {
  if (tds->res_info && tds->res_info->rows_exist) {
  return NO_MORE_RESULTS;
--- 553,559 ----
     tds = dbproc->tds_socket;

     retcode = tds_process_result_tokens(tds);
! if (DBDEAD(dbproc)) return 0;
     if (retcode == TDS_NO_MORE_RESULTS) {
  if (tds->res_info && tds->res_info->rows_exist) {
  return NO_MORE_RESULTS;
***************
*** 1255,1261 ****
  }
  DBBOOL DBDEAD(DBPROCESS *dbproc)
  {
! if(dbproc)
  return FALSE;
  else
  return TRUE;
--- 1255,1262 ----
  }
  DBBOOL DBDEAD(DBPROCESS *dbproc)
  {
! /* GW added check for socket validity */
! if(dbproc && dbproc->tds_socket->s)
  return FALSE;
  else
  return TRUE;
***************
*** 1559,1564 ****
--- 1560,1566 ----

  /* read the end token */
  marker = tds_get_byte(dbproc->tds_socket);
+ if (DBDEAD(dbproc) return FAIL; /* GW */
  tds_process_default_tokens(dbproc->tds_socket, marker);
  if (marker != TDS_DONE_TOKEN) {
  return FAIL;
Only in newfreetds/src/tds: .deps
diff -b -B -c -x Mak* -x config* -r freetds/src/tds/read.c
newfreetds/src/tds/read.c
*** freetds/src/tds/read.c Sun Nov 28 04:44:30 1999
--- newfreetds/src/tds/read.c Mon Jan 24 16:33:46 2000
***************
*** 19,30 ****
--- 19,36 ----

  #include <unistd.h>

+ #include <string.h>
+ #include <errno.h>
+ #include <malloc.h>
+ /* GW ADDED */
+
  #include "tdsutil.h"

  static char  software_version[]   = "$Id: read.c,v 1.12 1999/11/28
04:44:30 camber Exp $";
  static void *no_unused_var_warn[] = {software_version,
                                       no_unused_var_warn};

+ extern int tds_client_msg (TDSSOCKET *, int, int, int, int, char *); /* GW
added for -Wall... */

  /*
  ** Return a single byte from the input buffer
***************
*** 32,39 ****
  unsigned char tds_get_byte(TDSSOCKET *tds)
  {
  if (tds->in_pos >= tds->in_len) {
! if(!tds_read_packet(tds))
! return (0);
  }
  return tds->in_buf[tds->in_pos++];
  }
--- 38,46 ----
  unsigned char tds_get_byte(TDSSOCKET *tds)
  {
  if (tds->in_pos >= tds->in_len) {
! if((!(tds->s)) || !tds_read_packet(tds))
! return 0;
! /* GW CHANGED */
  }
  return tds->in_buf[tds->in_pos++];
  }
***************
*** 176,181 ****
--- 183,198 ----
  /* Read in the packet header.  We use this to figure out our packet
  ** length */
  if ((len = read(tds->s, header, 8)) < 8 ) {
+     if (len < 0) {
+       fprintf (stderr, "read returned %d\nErr no: %d (%s)\n", len, errno,
strerror(errno));
+       tds_client_msg(tds, 10018, 9, 0, 0, "The connection was closed");
+       close(tds->s);
+       tds->s=0;
+       tds->in_pos=0;
+       tds->in_len=0;
+       return 0;
+ /* GW ADDED */
+     }
  /*  Not sure if this is the best way to do the error
  **  handling here but this is the way it is currently
  **  being done. */
diff -b -B -c -x Mak* -x config* -r freetds/src/tds/token.c
newfreetds/src/tds/token.c
*** freetds/src/tds/token.c Wed Dec  1 03:20:35 1999
--- newfreetds/src/tds/token.c Mon Jan 24 16:00:38 2000
***************
*** 209,215 ****
  /* get_incoming(tds->s); */
  do {
  marker=tds_get_byte(tds);
! tdsdump_log("%L processing result tokens.  marker is  %x\n", marker);

  switch(marker) {
        case TDS_ERR_TOKEN:
--- 209,217 ----
  /* get_incoming(tds->s); */
  do {
  marker=tds_get_byte(tds);
! /* GW changed */
! if (tds->s) {
! tdsdump_log("%L processing result tokens.  marker is  %x\n", marker);

  switch(marker) {
        case TDS_ERR_TOKEN:
***************
*** 273,279 ****
  tds_process_default_tokens(tds, marker);
  break;
  }
! } while (!is_end_token(marker) || more_results);

  tds->state=TDS_COMPLETED;

--- 275,296 ----
  tds_process_default_tokens(tds, marker);
  break;
  }
! }
! } while ((tds->s) && (!is_end_token(marker) || more_results));
!
! if (!(tds->s)) return 0;
!
! /*
!
! while condition and above if condition added by GW.
!
! Do we need to check here, or should we just return before the
! while statement?
!
! ATM I'm checking here in case the state of tds->s could change
! during any of the while loop -- is this feasible?
!
! */

  tds->state=TDS_COMPLETED;





More information about the FreeTDS mailing list