move WSAStartup() and WSACleanup() out of per-object methods into per-library init...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 4 Dec 2014 15:07:11 +0000 (10:07 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 4 Dec 2014 15:07:11 +0000 (10:07 -0500)
libs/pbd/crossthread.win.cc
libs/pbd/pbd.cc

index 32f52fc12cb6537196ac89a53834272e42d28e57..5309916ddbfb07112e7db9f89e14e06e5c8512cd 100644 (file)
@@ -25,13 +25,6 @@ CrossThreadChannel::CrossThreadChannel (bool non_blocking)
        , receive_socket()
        , recv_address()
 {
-       WSADATA wsaData;
-
-       if(WSAStartup(MAKEWORD(1,1),&wsaData) != 0) {
-               std::cerr << "CrossThreadChannel::CrossThreadChannel() Winsock initialization failed with error: " << WSAGetLastError() << std::endl;
-               return;
-       }
-
        struct sockaddr_in send_address;
 
        // Create Send Socket
@@ -104,7 +97,6 @@ CrossThreadChannel::~CrossThreadChannel ()
 
        closesocket(send_socket);
        closesocket(receive_socket);
-       WSACleanup();
 }
 
 void
index 145e1b91a8080104d801e1a06974a6e2ee454919..858d870c1adf0a3024457ee1ed1a410e37b17e5e 100644 (file)
 #include "pbd/id.h"
 #include "pbd/enumwriter.h"
 
+#ifdef PLATFORM_WINDOWS
+#include <winsock2.h>
+#endif
+
 #include "i18n.h"
 
 extern void setup_libpbd_enums ();
@@ -68,6 +72,17 @@ PBD::init ()
        // Essential!!  Make sure that any files used by Ardour
        //              will be created or opened in BINARY mode!
        _fmode = O_BINARY;
+
+       WSADATA wsaData;
+
+       /* Initialize windows socket DLL for PBD::CrossThreadChannel
+        */
+       
+       if (WSAStartup(MAKEWORD(1,1),&wsaData) != 0) {
+               fatal << "Windows socket initialization failed with error: " << WSAGetLastError() << endmsg;
+               /*NOTREACHED*/
+               return;
+       }
 #endif
 
        if (!Glib::thread_supported()) {
@@ -89,5 +104,9 @@ PBD::init ()
 void
 PBD::cleanup ()
 {
+#ifdef PLATFORM_WINDOWS
+       WSACleanup();
+#endif 
+
        EnumWriter::destroy ();
 }