receive_and_send_encrypted_post_data(): Change two more log messages
[privoxy.git] / jbsockets.c
index 1fe56e1..556c927 100644 (file)
@@ -8,7 +8,7 @@
  *                on many platforms.
  *
  * Copyright   :  Written by and Copyright (C) 2001-2017 the
- *                Privoxy team. http://www.privoxy.org/
+ *                Privoxy team. https://www.privoxy.org/
  *
  *                Based on the Internet Junkbuster originally written
  *                by and Copyright (C) 1997 Anonymous Coders and
@@ -218,7 +218,7 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client
 #endif
    int connect_failed;
    /*
-    * XXX: Initializeing it here is only necessary
+    * XXX: Initializing it here is only necessary
     *      because not all situations are properly
     *      covered yet.
     */
@@ -673,6 +673,60 @@ int write_socket(jb_socket fd, const char *buf, size_t len)
 }
 
 
+/*********************************************************************
+ *
+ * Function    :  write_socket_delayed
+ *
+ * Description :  Write the contents of buf (for n bytes) to
+ *                socket fd, optionally delaying the operation.
+ *
+ * Parameters  :
+ *          1  :  fd = File descriptor (aka. handle) of socket to write to.
+ *          2  :  buf = Pointer to data to be written.
+ *          3  :  len = Length of data to be written to the socket "fd".
+ *          4  :  delay = Delay in milliseconds.
+ *
+ * Returns     :  0 on success (entire buffer sent).
+ *                nonzero on error.
+ *
+ *********************************************************************/
+int write_socket_delayed(jb_socket fd, const char *buf, size_t len, unsigned int delay)
+{
+   size_t i = 0;
+
+   if (delay == 0)
+   {
+      return write_socket(fd, buf, len);
+   }
+
+   while (i < len)
+   {
+      size_t write_length;
+      enum {MAX_WRITE_LENGTH = 10};
+
+      if ((i + MAX_WRITE_LENGTH) > len)
+      {
+         write_length = len - i;
+      }
+      else
+      {
+         write_length = MAX_WRITE_LENGTH;
+      }
+
+      privoxy_millisleep(delay);
+
+      if (write_socket(fd, buf + i, write_length) != 0)
+      {
+         return 1;
+      }
+      i += write_length;
+   }
+
+   return 0;
+
+}
+
+
 /*********************************************************************
  *
  * Function    :  read_socket
@@ -1014,6 +1068,10 @@ int bind_port(const char *hostnam, int portnum, int backlog, jb_socket *pfd)
    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
 #endif /* ndef _WIN32 */
 
+#ifdef IP_FREEBIND
+   setsockopt(fd, IPPROTO_IP, IP_FREEBIND, (char *)&one, sizeof(one));
+#endif
+
 #ifdef HAVE_RFC2553
    if (bind(fd, rp->ai_addr, rp->ai_addrlen) < 0)
 #else
@@ -1265,7 +1323,7 @@ int accept_connection(struct client_state * csp, jb_socket fds[])
 #endif
    jb_socket afd;
 #if defined(_WIN32) || defined(__OS2__)
-   /* Wierdness - fix a warning. */
+   /* Weirdness - fix a warning. */
    int c_length;
 #else
    socklen_t c_length;