-/* Bind the local port PORT. This does all the necessary work, which
- is creating a socket, setting SO_REUSEADDR option on it, then
- calling bind() and listen(). If *PORT is 0, a random port is
- chosen by the system, and its value is stored to *PORT. The
- internal variable MPORT is set to the value of the ensuing master
- socket. Call acceptport() to block for and accept a connection. */
-uerr_t
-bindport (unsigned short *port, int family)
-{
- int optval = 1;
- wget_sockaddr srv;
- memset (&srv, 0, sizeof (wget_sockaddr));
-
- msock = -1;
-
- if ((msock = socket (family, SOCK_STREAM, 0)) < 0)
- return CONSOCKERR;
- if (setsockopt (msock, SOL_SOCKET, SO_REUSEADDR,
- (char *)&optval, sizeof (optval)) < 0)
- return CONSOCKERR;
-
- resolve_bind_address ();
- wget_sockaddr_set_address (&srv, ip_default_family, htons (*port),
- bind_address_resolved ? &bind_address : NULL);
- if (bind (msock, &srv.sa, sockaddr_len ()) < 0)
- {
- CLOSE (msock);
- msock = -1;
- return BINDERR;
- }
- DEBUGP (("Master socket fd %d bound.\n", msock));
- if (!*port)
- {
- /* #### addrlen should be a 32-bit type, which int is not
- guaranteed to be. Oh, and don't try to make it a size_t,
- because that can be 64-bit. */
- int sa_len = sockaddr_len ();
- if (getsockname (msock, &srv.sa, &sa_len) < 0)
- {
- CLOSE (msock);
- msock = -1;
- return CONPORTERR;
- }
- *port = wget_sockaddr_get_port (&srv);
- DEBUGP (("using port %i.\n", *port));
- }
- if (listen (msock, 1) < 0)
- {
- CLOSE (msock);
- msock = -1;
- return LISTENERR;
- }
- return BINDOK;
-}
-
-#ifdef HAVE_SELECT
-/* Wait for file descriptor FD to be available, timing out after
- MAXTIME seconds. "Available" means readable if writep is 0,
- writeable otherwise.
+#ifdef WINDOWS
+# define read(fd, buf, cnt) recv (fd, buf, cnt, 0)
+# define write(fd, buf, cnt) send (fd, buf, cnt, 0)
+# define close(fd) closesocket (fd)
+#endif