Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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" To: , Subject: CYGWIN Socket write() problem in 1.1.7 DLL Date: Fri, 5 Jan 2001 13:06:03 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit 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