Regenerate for 3.0.26 (STABLE)
[privoxy.git] / jbsockets.c
index 6a89f68..0f1ba16 100644 (file)
@@ -1,14 +1,13 @@
-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.139 2016/12/24 16:00:49 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
  *
  * Purpose     :  Contains wrappers for system-specific sockets code,
- *                so that the rest of Junkbuster can be more
+ *                so that the rest of Privoxy can be more
  *                OS-independent.  Contains #ifdefs to make this work
  *                on many platforms.
  *
- * Copyright   :  Written by and Copyright (C) 2001-2016 the
+ * Copyright   :  Written by and Copyright (C) 2001-2017 the
  *                Privoxy team. http://www.privoxy.org/
  *
  *                Based on the Internet Junkbuster originally written
@@ -107,8 +106,6 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.139 2016/12/24 16:00:49 fabia
 #define AI_NUMERICSERV 0
 #endif
 
-const char jbsockets_h_rcs[] = JBSOCKETS_H_VERSION;
-
 /*
  * Maximum number of gethostbyname(_r) retries in case of
  * soft errors (TRY_AGAIN).
@@ -116,8 +113,6 @@ const char jbsockets_h_rcs[] = JBSOCKETS_H_VERSION;
  */
 #define MAX_DNS_RETRIES 10
 
-#define MAX_LISTEN_BACKLOG 128
-
 #ifdef HAVE_RFC2553
 static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client_state *csp);
 #else
@@ -128,7 +123,8 @@ static jb_socket no_rfc2553_connect_to(const char *host, int portnum, struct cli
  *
  * Function    :  set_no_delay_flag
  *
- * Description :  Disables TCP coalescence for the given socket.
+ * Description :  Disables the Nagle algorithm (TCP send coalescence)
+ *                for the given socket.
  *
  * Parameters  :
  *          1  :  fd = The file descriptor to operate on
@@ -370,10 +366,29 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client
 #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) */
 
 #ifdef HAVE_POLL
-   poll_fd[0].fd = fd;
-   poll_fd[0].events = POLLOUT;
+      poll_fd[0].fd = fd;
+      poll_fd[0].events = POLLOUT;
 
-   if (poll(poll_fd, 1, 30000) > 0)
+      retval = poll(poll_fd, 1, 30000);
+      if (retval == 0)
+      {
+         if (rp->ai_next != NULL)
+         {
+            /* Log this now as we'll try another address next */
+            log_error(LOG_LEVEL_CONNECT,
+               "Could not connect to [%s]:%s: Operation timed out.",
+               csp->http->host_ip_addr_str, service);
+         }
+         else
+         {
+            /*
+             * This is the last address, don't log this now
+             * as it would result in a duplicated log message.
+             */
+            socket_error = ETIMEDOUT;
+         }
+      }
+      else if (retval > 0)
 #else
       /* wait for connection to complete */
       FD_ZERO(&wfds);
@@ -871,14 +886,15 @@ void drain_and_close_socket(jb_socket fd)
  * Parameters  :
  *          1  :  hostnam = TCP/IP address to bind/listen to
  *          2  :  portnum = port to listen on
- *          3  :  pfd = pointer used to return file descriptor.
+ *          3  :  backlog = Listen backlog
+ *          4  :  pfd = pointer used to return file descriptor.
  *
  * Returns     :  if success, returns 0 and sets *pfd.
  *                if failure, returns -3 if address is in use,
  *                                    -2 if address unresolvable,
  *                                    -1 otherwise
  *********************************************************************/
-int bind_port(const char *hostnam, int portnum, jb_socket *pfd)
+int bind_port(const char *hostnam, int portnum, int backlog, jb_socket *pfd)
 {
 #ifdef HAVE_RFC2553
    struct addrinfo hints;
@@ -1053,7 +1069,7 @@ int bind_port(const char *hostnam, int portnum, jb_socket *pfd)
    }
 #endif /* ndef HAVE_RFC2553 */
 
-   while (listen(fd, MAX_LISTEN_BACKLOG) == -1)
+   while (listen(fd, backlog) == -1)
    {
       if (errno != EINTR)
       {
@@ -1358,12 +1374,6 @@ int accept_connection(struct client_state * csp, jb_socket fds[])
 #else
    do
    {
-#if defined(FEATURE_ACCEPT_FILTER) && defined(SO_ACCEPTFILTER)
-      struct accept_filter_arg af_options;
-      bzero(&af_options, sizeof(af_options));
-      strlcpy(af_options.af_name, "httpready", sizeof(af_options.af_name));
-      setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &af_options, sizeof(af_options));
-#endif
       afd = accept (fd, (struct sockaddr *) &client, &c_length);
    } while (afd < 0 && errno == EINTR);
    if (afd < 0)
@@ -1577,7 +1587,6 @@ int socket_is_still_alive(jb_socket sfd)
 {
    char buf[10];
    int no_data_waiting;
-
 #ifdef HAVE_POLL
    int poll_result;
    struct pollfd poll_fd[1];