Ruediger Pluem wrote:
Reposting what I sent to Mladen in private. Just missed that
his address was in to and not [email protected] :-)
OK. Here is the new code used in mod_jk
It works for the selected set of platforms
(windows, linux, solaris)
Any comments about other platforms?
int jk_is_socket_connected(jk_sock_t sock)
{
fd_set fd;
struct timeval tv;
int rc;
FD_ZERO(&fd);
FD_SET(sock, &fd);
/* Wait one microsecond */
tv.tv_sec = 0;
tv.tv_usec = 1;
do {
rc = select((int)sock + 1, &fd, NULL, NULL, &tv);
#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
errno = WSAGetLastError() - WSABASEERR;
#endif
} while (rc == -1 && errno == EINTR);
if (rc == 0) {
/* If we get a timeout, then we are still connected */
return 1;
}
else if (rc == 1) {
#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
u_long nr;
if (ioctlsocket(sock, FIONREAD, &nr) == 0) {
return nr == 0 ? 0 : 1;
}
#else
int nr;
if (ioctl(sock, FIONREAD, (void*)&nr) == 0) {
return nr == 0 ? 0 : 1;
}
#endif
}
return 0;
}