[1962] in Moira Commits
/svn/moira r4101 - trunk/moira/lib
daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Wed Mar 6 11:37:31 2013
Date: Wed, 6 Mar 2013 11:37:24 -0500
From: Garry Zacheiss <zacheiss@MIT.EDU>
Message-Id: <201303061637.r26GbOer014319@drugstore.mit.edu>
To: moira-commits@MIT.EDU
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: zacheiss
Date: 2013-03-06 11:37:24 -0500 (Wed, 06 Mar 2013)
New Revision: 4101
Modified:
trunk/moira/lib/mr_connect.c
Log:
From rbasch: on modern Windows, we need to call WSAStartup().
Modified: trunk/moira/lib/mr_connect.c
===================================================================
--- trunk/moira/lib/mr_connect.c 2013-02-28 22:55:34 UTC (rev 4100)
+++ trunk/moira/lib/mr_connect.c 2013-03-06 16:37:24 UTC (rev 4101)
@@ -37,13 +37,14 @@
#ifdef HAVE_HESIOD
#include <hesiod.h>
+#endif
+
#ifdef _WIN32
-/* This is declared in wshelper's resolv.h, but the definition of
- * the putlong macro conflicts with Moira's
+/* This is declared in wshelper's headers, but those also include a
+ * definition of the putlong macro which conflicts with Moira's.
*/
struct hostent * WINAPI rgethostbyname(char *name);
#endif
-#endif
RCSID("$HeadURL$ $Id$");
@@ -53,6 +54,10 @@
int _mr_conn = 0;
static char *mr_server_host = NULL;
+#ifdef _WIN32
+static int mr_conn_wsaStart = 0;
+#endif
+
/* mrgdb compatibility magic
The data looks like this:
@@ -96,6 +101,11 @@
int mr_connect(char *server)
{
char *port, **pp, *sbuf = NULL;
+#ifdef _WIN32
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int err;
+#endif
if (_mr_conn)
return MR_ALREADY_CONNECTED;
@@ -105,6 +115,14 @@
if (!server || (strlen(server) == 0))
server = getenv("MOIRASERVER");
+#ifdef _WIN32
+ wVersionRequested = MAKEWORD(2, 2);
+ err = WSAStartup(wVersionRequested, &wsaData);
+ if (err != 0)
+ return MR_CANT_CONNECT;
+ mr_conn_wsaStart++;
+#endif
+
#ifdef HAVE_HESIOD
if (!server || (strlen(server) == 0))
{
@@ -148,7 +166,7 @@
int ok = 0;
int on = 1; /* Value variable for setsockopt() */
-#if defined(_WIN32) && defined(HAVE_HESIOD)
+#if defined(_WIN32)
shost = rgethostbyname(server);
#else
shost = gethostbyname(server);
@@ -232,6 +250,13 @@
_mr_conn = 0;
free(mr_server_host);
mr_server_host = NULL;
+#ifdef _WIN32
+ if (mr_conn_wsaStart > 0)
+ {
+ WSACleanup();
+ mr_conn_wsaStart--;
+ }
+#endif
return MR_SUCCESS;
}