]> sjero.net Git - wget/blobdiff - src/connect.c
[svn] Allow decimal values for --timeout, --wait, and --waitretry.
[wget] / src / connect.c
index 042f9e579c22d1e08b3d6155f3b5286d14dd2941..5f927647079acfba2aacba40072182f07532eb38 100644 (file)
@@ -15,11 +15,22 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with Wget; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+In addition, as a special exception, the Free Software Foundation
+gives permission to link the code of its release of Wget with the
+OpenSSL project's "OpenSSL" library (or with modified versions of it
+that use the same license as the "OpenSSL" library), and distribute
+the linked executables.  You must obey the GNU General Public License
+in all respects for all of the code used other than "OpenSSL".  If you
+modify this file, you may extend this exception to your version of the
+file, but you are not obligated to do so.  If you do not wish to do
+so, delete this exception statement from your version.  */
 
 #include <config.h>
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
@@ -165,6 +176,20 @@ connect_to_one (ip_address *addr, unsigned short port, int silent)
   if (sock < 0)
     goto out;
 
+#ifdef SO_RCVBUF
+  /* For very small rate limits, set the buffer size (and hence,
+     hopefully, the size of the kernel window) to the size of the
+     limit.  */
+  if (opt.limit_rate && opt.limit_rate < 8192)
+    {
+      int bufsize = opt.limit_rate;
+      if (bufsize < 512)
+       bufsize = 512;
+      setsockopt (sock, SOL_SOCKET, SO_RCVBUF,
+                 (char *)&bufsize, sizeof (bufsize));
+    }
+#endif
+
   resolve_bind_address ();
   if (bind_address_resolved)
     {
@@ -281,9 +306,12 @@ bindport (unsigned short *port, int family)
 
   if ((msock = socket (family, SOCK_STREAM, 0)) < 0)
     return CONSOCKERR;
+
+#ifdef SO_REUSEADDR
   if (setsockopt (msock, SOL_SOCKET, SO_REUSEADDR,
                  (char *)&optval, sizeof (optval)) < 0)
     return CONSOCKERR;
+#endif
 
   resolve_bind_address ();
   wget_sockaddr_set_address (&srv, ip_default_family, htons (*port),
@@ -327,7 +355,7 @@ bindport (unsigned short *port, int family)
    Returns 1 if FD is available, 0 for timeout and -1 for error.  */
 
 int
-select_fd (int fd, int maxtime, int writep)
+select_fd (int fd, double maxtime, int writep)
 {
   fd_set fds;
   fd_set *rd = NULL, *wrt = NULL;
@@ -338,8 +366,8 @@ select_fd (int fd, int maxtime, int writep)
   FD_SET (fd, &fds);
   *(writep ? &wrt : &rd) = &fds;
 
-  tmout.tv_sec = maxtime;
-  tmout.tv_usec = 0;
+  tmout.tv_sec = (long)maxtime;
+  tmout.tv_usec = 1000000L * (maxtime - (long)maxtime);
 
   do
     result = select (fd + 1, rd, wrt, NULL, &tmout);
@@ -402,7 +430,7 @@ conaddr (int fd, ip_address *ip)
 
   switch (mysrv.sa.sa_family)
     {
-#ifdef INET6
+#ifdef ENABLE_IPV6
     case AF_INET6:
       memcpy (ip, &mysrv.sin6.sin6_addr, 16);
       return 1;