aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorSean McNamara <smcnam@gmail.com>2009-03-27 18:02:31 +0100
committerMax Kellermann <max@duempel.org>2009-03-27 18:02:31 +0100
commit9c63ffa546e0dff29252294c0cd310b2ecfa8531 (patch)
tree39ae63d25d252e5286151ebc59fdeb6c47b87e63 /src/main.c
parentb91517e76115eca222e84bacb839e84ca5898a0e (diff)
downloadmpd-9c63ffa546e0dff29252294c0cd310b2ecfa8531.tar.gz
mpd-9c63ffa546e0dff29252294c0cd310b2ecfa8531.tar.xz
mpd-9c63ffa546e0dff29252294c0cd310b2ecfa8531.zip
Winsock2 is needed on MinGW (or other pure Win32 toolchains) for
networking, select(), ntohl(), etc.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index a8e6ddae5..5035a4836 100644
--- a/src/main.c
+++ b/src/main.c
@@ -75,6 +75,11 @@
#include <locale.h>
#endif
+#ifdef WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif
+
enum {
DEFAULT_BUFFER_SIZE = 2048,
DEFAULT_BUFFER_BEFORE_PLAY = 10,
@@ -136,6 +141,31 @@ openDB(const Options *options)
}
/**
+ * Windows-only initialization of the Winsock2 library.
+ */
+#ifdef WIN32
+static void winsock_init(void)
+{
+ WSADATA sockinfo;
+ int retval;
+
+ retval = WSAStartup(MAKEWORD(2, 2), &sockinfo);
+ if(retval != 0)
+ {
+ g_error("Attempt to open Winsock2 failed; error code %d\n",
+ retval);
+ }
+
+ if (LOBYTE(sockinfo.wVersion) != 2)
+ {
+ g_error("We use Winsock2 but your version is either too new or "
+ "old; please install Winsock 2.x\n");
+ }
+
+}
+#endif
+
+/**
* Initialize the decoder and player core, including the music pipe.
*/
static void
@@ -212,6 +242,9 @@ int main(int argc, char *argv[])
/* enable GLib's thread safety code */
g_thread_init(NULL);
+#ifdef WIN32
+ winsock_init();
+#endif
idle_init();
dirvec_init();
songvec_init();
@@ -339,6 +372,9 @@ int main(int argc, char *argv[])
idle_deinit();
stats_global_finish();
daemonize_finish();
+#ifdef WIN32
+ WSACleanup();
+#endif
close_log_files();
return EXIT_SUCCESS;