Mail Archives: cygwin/2001/01/04/19:08:18
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 -