From e89333b098ab48d948391e0bdce91d24f668604c Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Mon, 19 Jul 1999 22:23:43 +0000 Subject: [PATCH] A hack to get _MD_unix_get_nonblocking_connect_error to work for Neutrino. This patch is contributed by Jerry L. Kirk . git-svn-id: svn://10.0.0.236/trunk@40173 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/nsprpub/pr/src/md/unix/unix.c | 70 ++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/mozilla/nsprpub/pr/src/md/unix/unix.c b/mozilla/nsprpub/pr/src/md/unix/unix.c index a4d17425ec9..4eb75d1b495 100644 --- a/mozilla/nsprpub/pr/src/md/unix/unix.c +++ b/mozilla/nsprpub/pr/src/md/unix/unix.c @@ -38,6 +38,10 @@ #include #endif +#if defined(NTO) +#include +#endif + /* * Make sure _PRSockLen_t is 32-bit, because we will cast a PRUint32* or * PRInt32* pointer to a _PRSockLen_t* pointer. @@ -3358,7 +3362,71 @@ void _PR_Unblock_IO_Wait(PRThread *thr) int _MD_unix_get_nonblocking_connect_error(int osfd) { -#if defined(NCR) || defined(UNIXWARE) || defined(SNI) || defined(NEC) +#if defined(NTO) + /* Neutrino does not support the SO_ERROR socket option */ + PRInt32 rv; + PRNetAddr addr; + _PRSockLen_t addrlen = sizeof(addr); + + /* Test to see if we are using the Tiny TCP/IP Stack or the Full one. */ + struct statvfs superblock; + rv = fstatvfs(osfd, &superblock); + if (rv == 0) { + if (strcmp(superblock.f_basetype, "ttcpip") == 0) { + /* Using the Tiny Stack! */ + rv = getpeername(osfd, (struct sockaddr *) &addr, + (_PRSockLen_t *) &addrlen); + if (rv == -1) { + int errno_copy = errno; /* make a copy so I don't + * accidentally reset */ + + if (errno_copy == ENOTCONN) { + struct stat StatInfo; + rv = fstat(osfd, &StatInfo); + if (rv == 0) { + time_t current_time = time(NULL); + + /* + * this is a real hack, can't explain why it + * works it just does + */ + if (abs(current_time - StatInfo.st_atime) < 5) { + return ECONNREFUSED; + } else { + return ETIMEDOUT; + } + } else { + return ECONNREFUSED; + } + } else { + return errno_copy; + } + } else { + /* No Error */ + return 0; + } + } else { + /* Have the FULL Stack which supports SO_ERROR */ + /* Hasn't been written yet, never been tested! */ + /* Jerry.Kirk@Nexwarecorp.com */ + + int err; + _PRSockLen_t optlen = sizeof(err); + + printf("_MD_unix_get_nonblocking_connect_error: " + "Assuming Large TCP/IP Stack -REVISIT- Never Tested!\n"); + + if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, + (char *) &err, &optlen) == -1) { + return errno; + } else { + return err; + } + } + } else { + return ECONNREFUSED; + } +#elif defined(NCR) || defined(UNIXWARE) || defined(SNI) || defined(NEC) /* * getsockopt() fails with EPIPE, so use getmsg() instead. */