workaround for vista service automatic WSAStartup() crash issue

This commit is contained in:
Aleksandar Fabijanic
2010-04-03 14:09:48 +00:00
parent bf87d53ac7
commit 8d928d0c00
2 changed files with 39 additions and 5 deletions

View File

@@ -89,4 +89,22 @@
#endif #endif
namespace Poco {
namespace Net {
void initializeNetwork();
/// Initialize the network subsystem.
/// Calls WSAStartup() on Windows, does nothing
/// on other platforms.
void uninitializeNetwork();
/// Uninitialize the network subsystem.
/// Calls WSACleanup() on Windows, does nothing
/// on other platforms.
} } // namespace Poco::Net
#endif // Net_Net_INCLUDED #endif // Net_Net_INCLUDED

View File

@@ -50,7 +50,7 @@ using Poco::IOException;
// //
// Automatic initialization of Windows networking // Automatic initialization of Windows networking
// //
#if defined(_WIN32) #if defined(_WIN32) && !defined(POCO_NET_NO_AUTOMATIC_WSASTARTUP)
namespace namespace
{ {
class NetworkInitializer class NetworkInitializer
@@ -58,14 +58,12 @@ namespace
public: public:
NetworkInitializer() NetworkInitializer()
{ {
WORD version = MAKEWORD(2, 2); Poco::Net::initializeNetwork();
WSADATA data;
WSAStartup(version, &data);
} }
~NetworkInitializer() ~NetworkInitializer()
{ {
WSACleanup(); Poco::Net::uninitializeNetwork();
} }
}; };
@@ -236,4 +234,22 @@ void DNS::error(int code, const std::string& arg)
} }
void initializeNetwork()
{
#if defined(_WIN32)
WORD version = MAKEWORD(2, 2);
WSADATA data;
WSAStartup(version, &data);
#endif // _WIN32
}
void uninitializeNetwork()
{
#if defined(_WIN32)
WSACleanup();
#endif // _WIN32
}
} } // namespace Poco::Net } } // namespace Poco::Net