-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.117 2012/10/17 18:01:34 fabiankeil Exp $";
+const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.123 2013/03/06 21:06:18 diem Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
#endif
-#ifdef FEATURE_CONNECTION_KEEP_ALIVE
#ifdef HAVE_POLL
#ifdef __GLIBC__
#include <sys/poll.h>
#include <poll.h>
#endif /* def __GLIBC__ */
#endif /* HAVE_POLL */
-#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
#include "project.h"
*
* Parameters :
* 1 : host = hostname to connect to
- * 2 : portnum = port to connent on (XXX: should be unsigned)
+ * 2 : portnum = port to connect to (XXX: should be unsigned)
* 3 : csp = Current client state (buffers, headers, etc...)
*
* Returns : JB_INVALID_SOCKET => failure, else it is the socket
continue;
}
+#ifndef _WIN32
+ if (fd >= FD_SETSIZE)
+ {
+ log_error(LOG_LEVEL_ERROR,
+ "Server socket number too high to use select(): %d >= %d",
+ fd, FD_SETSIZE);
+ close_socket(fd);
+ return JB_INVALID_SOCKET;
+ }
+#endif
+
#ifdef TCP_NODELAY
{ /* turn off TCP coalescence */
int mi = 1;
return(JB_INVALID_SOCKET);
}
+#ifndef _WIN32
+ if (fd >= FD_SETSIZE)
+ {
+ log_error(LOG_LEVEL_ERROR,
+ "Server socket number too high to use select(): %d >= %d",
+ fd, FD_SETSIZE);
+ close_socket(fd);
+ return JB_INVALID_SOCKET;
+ }
+#endif
+
#ifdef TCP_NODELAY
{ /* turn off TCP coalescence */
int mi = 1;
{
char drainage[500];
+ if (!data_is_available(fd, 0))
+ {
+ /*
+ * If there is no data available right now, don't try
+ * to drain the socket as read_socket() could block.
+ */
+ break;
+ }
+
bytes_drained = read_socket(fd, drainage, sizeof(drainage));
if (bytes_drained < 0)
{
struct sockaddr_in server;
struct hostent *host = NULL;
#endif /* HAVE_RFC2553 */
-#if defined(_WIN32) || defined(__OS2__) || defined(__APPLE_CC__) || defined(AMIGA)
+#if defined(_WIN32) || defined(__OS2__) || defined(AMIGA)
/* according to accept_connection() this fixes a warning. */
int s_length, s_length_provided;
#else
* configured with --disable-ipv6-support.
* The proper fix is to not use NI_MAXSERV in
* that case. It works by accident on other platforms
- * as <netdb.h> in included unconditionally there.
+ * as <netdb.h> is included unconditionally there.
*/
#ifndef NI_MAXSERV
#define NI_MAXSERV 32
struct sockaddr_in client;
#endif
jb_socket afd;
-#if defined(_WIN32) || defined(__OS2__) || defined(__APPLE_CC__) || defined(AMIGA)
+#if defined(_WIN32) || defined(__OS2__) || defined(AMIGA)
/* Wierdness - fix a warning. */
int c_length;
#else
}
#endif
+#ifndef _WIN32
+ if (afd >= FD_SETSIZE)
+ {
+ log_error(LOG_LEVEL_ERROR,
+ "Client socket number too high to use select(): %d >= %d",
+ afd, FD_SETSIZE);
+ close_socket(afd);
+ return 0;
+ }
+#endif
+
csp->cfd = afd;
#ifdef HAVE_RFC2553
csp->ip_addr_str = malloc(NI_MAXHOST);
}
-#ifdef FEATURE_CONNECTION_KEEP_ALIVE
/*********************************************************************
*
* Function : socket_is_still_alive
return (no_data_waiting || (1 == recv(sfd, buf, 1, MSG_PEEK)));
}
-#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
/*