delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/01/04/19:08:18

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <009001c0775b$50b14ce0$574bb4ca@private>
From: "David McNab" <david AT rebirthing DOT co DOT nz>
To: <Markus DOT Hoenicka AT uth DOT tmc DOT edu>, <cygwin AT cygwin DOT com>
Subject: CYGWIN Socket write() problem in 1.1.7 DLL
Date: Fri, 5 Jan 2001 13:06:03 -0800
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700

I note from the message archives that people have had some problems with
CYGWIN-built apps writing to sockets.

In a nutshell, the problem is that data written to the socket doesn't always
make it to the recipient. When the CYGWIN-built program closes the socket
after the write(), the client at the other end gets a disconnect failure and
doesn't receive the data.

I've had the same problem. I'm helping with testing and debugging of a
CYGWIN-based (v1.1.1.7 dll) proxy server program, for which I run Microsoft
Internet Explorer as a client. On page fetches, Internet Explorer often
complains that the 'connection to the server was reset'.

Has anyone found anything yet that can shed light?

I've had *partial* success, by putting the socket into blocking mode and
sleeping for a bit prior to closing it (code excerpt enclosed at end).
However, this only cuts incidences of the problem by about 60%. Still
happens when writing larger amounts of data.

I also tried a lingering close() (again see code excerpt), but this seems to
have no effect.

I must admit that, despite being a C/Unix programmer in the past, I am very
new to the CYGWIN environment.

Somebody, please help.

David McNab
david AT rebirthing DOT co DOT nz

CODE EXCERPT FOLLOWS:

#ifndef HACK
 /* flush out the client socket - set it to blocking, then write to it */
 client_sock_flags=fcntl(client,F_GETFL,0);
    if(client_sock_flags!=-1)
    {
        PrintMessage(Important,"Trying to flush socket to client before
closing it");

        /* disable blocking */
  fcntl(client,F_SETFL,client_sock_flags ^ O_NONBLOCK);

  /* sent it a byte now that calls are blocking */
  write(client, &endchar, 1);

  /* hang about for a bit */
  sleep(5);
    }
#endif

#ifndef TRY_A_LINGERING_CLOSE
 /* this was suggested by CYGWIN people, but doesn't seem to do anything */
 {
  struct linger lingeropt;

  lingeropt.l_onoff = 1;
  lingeropt.l_linger = 15;

  if (setsockopt(client, SOL_SOCKET, SO_LINGER, &lingeropt,
sizeof(lingeropt)) < 0)
  {
   switch errno
   {
   case EBADF:
    PrintMessage(Important, "setsockopt error: EBADF");
    break;
   case ENOTSOCK:
    PrintMessage(Important, "setsockopt error: ENOTSOCK");
    break;
   case ENOPROTOOPT:
    PrintMessage(Important, "setsockopt error: ENOPROTOPT");
    break;
   default:
    PrintMessage(Important, "setsockopt: unknown error");
   }
  }
  else
   PrintMessage(Important, "setsockopt succeeded");
 }
#endif
/* sleep(3);*/
    CloseSocket(client); /* a small wrapper for 'close(client)' */




--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019