Skip to Content.
Sympa Menu

freetds - Re: patch for SIGPIPE in tds_write_packet

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Brian Bruns <camber AT umcc.ais.org>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: Re: patch for SIGPIPE in tds_write_packet
  • Date: Wed, 26 Jan 2000 19:57:21 -0500 (EST)


Ok, code is commited to CVS and I added your name to the AUTHORS file (let
me know if you want it to say something different).

Brian


?Brian
On Tue, 25 Jan 2000, Geoff Winkless wrote:

> So for some reason, when MS SQL disconnects you get a SIGPIPE signal when
> trying to write to the fd, whereas with Sybase this doesn't happen.
>
> Anyway, this code seems to fix that, I'm not sure if we'd need to put a
> SIGPIPE check around the read (do you get bad pipe or does it just return
> EIO, EBADF or EINVAL??).
>
> There will probably be more places to add in checks for tds->s.
>
> And I have yet another gripe with gdb. For some reason it crashes when I try
> any signal handling at all. Joy. I guess I ought to upgrade gdb... ;-)
>
> Geoff
>
> *** oldwrite.c Tue Jan 25 16:08:07 2000
> --- write.c Tue Jan 25 16:03:59 2000
> ***************
> *** 21,26 ****
> --- 21,27 ----
> #include "tdsutil.h"
> #include <unistd.h>
> #include <stdlib.h>
> + #include <signal.h> /* GW ADDED */
>
>
> static char software_version[] = "$Id: write.c,v 1.10 1999/11/28
> 04:44:31 camber Exp $";
> ***************
> *** 88,95 ****
> --- 89,99 ----
> memset(tds->out_buf,'\0',512);
> tds->out_pos=8;
> }
> +
> int tds_write_packet(TDSSOCKET *tds,unsigned char final)
> {
> + static int retval;
> + void (*oldsig)(int);
> tds->out_buf[0]=tds->out_flag;
> tds->out_buf[1]=final;
> tds->out_buf[2]=(tds->out_pos)/256;
> ***************
> *** 99,106 ****
> }
>
> tdsdump_log("Sending packet @ %L\n%D\n", tds->out_buf,
> tds->out_pos);
>
> ! write(tds->s,tds->out_buf,tds->out_pos);
> /* for (i=0;i<tds->out_pos;i++) {
> printf ("%d:%d",i,tds->out_buf[i]);
> if (tds->out_buf[i]>=' ' && tds->out_buf[i]<'z')
> --- 103,128 ----
> }
>
> tdsdump_log("Sending packet @ %L\n%D\n", tds->out_buf, tds->out_pos);
> + oldsig=signal (SIGPIPE, SIG_IGN);
> + if (oldsig==SIG_ERR) {
> + fprintf(stderr, "TDS: Warning: Couldn't set SIGPIPE signal to be
> ignored\n");
> + }
> + retval=write(tds->s,tds->out_buf,tds->out_pos);
> +
> + if (signal(SIGPIPE, oldsig)==SIG_ERR) {
> + fprintf(stderr, "TDS: Warning: Couldn't reset SIGPIPE signal to previous
> value\n");
> + }
>
> ! if (retval < 0) {
> ! fprintf(stderr, "TDS: Write failed in tds_write_packet\nError: %d
> (%s)\n", errno, strerror(errno));
> ! tds_client_msg(tds, 10018, 9, 0, 0, "The connection was closed");
> ! tds->in_pos=0;
> ! tds->in_len=0;
> ! close(tds->s);
> ! tds->s=0;
> ! return 0;
> ! }
> ! /* GW added in check for write() returning <0 and SIGPIPE checking */
> /* for (i=0;i<tds->out_pos;i++) {
> printf ("%d:%d",i,tds->out_buf[i]);
> if (tds->out_buf[i]>=' ' && tds->out_buf[i]<'z')
> ***************
> *** 113,118 ****
> }
> int tds_flush_packet(TDSSOCKET *tds)
> {
> ! tds_write_packet(tds,0x01);
> ! tds_init_write_buf(tds);
> }
> --- 135,141 ----
> }
> int tds_flush_packet(TDSSOCKET *tds)
> {
> ! if (tds->s) tds_write_packet(tds,0x01);
> ! if (tds->s) tds_init_write_buf(tds);
> ! /* GW added check for tds->s */
> }
>
>
>
> ---
> You are currently subscribed to freetds as: camber AT ais.org
> To unsubscribe, forward this message to $subst('Email.Unsub')
>
>





Archive powered by MHonArc 2.6.24.

Top of Page