class socket_cleanup
{
private:
- static ::WSADATA* m_wsaInfo;
+ static ::WSADATA m_wsaInfo;
static int m_count;
- public:
- static void add(
+
+ static void startup(
unsigned char ver_major=ROAST_WINDOWS_SOCKET_DEFAULT_VER_MAJOR,
unsigned char ver_miner=ROAST_WINDOWS_SOCKET_DEFAULT_VER_MINER)
{
WORD wVersionRequested = MAKEWORD(ver_major, ver_miner);
- if ( ::WSAStartup(wVersionRequested, m_pWsaInfo) != 0 )
+ if ( ::WSAStartup(wVersionRequested, &m_wsaInfo) != 0 )
throw socket_exception(::WSAGetLastError(), "roast::socket_cleanup::add() ::WSAStartup() function was error.");
+
+ }
+ static void cleanup()
+ {
+ if ( ::WSACleanup() != 0 )
+ throw socket_exception(::WSAGetLastError(), "roast::socket_cleanup::free() ::WSACleanup() function was error.");
+ }
+
+ public:
+ static void add(
+ unsigned char ver_major=ROAST_WINDOWS_SOCKET_DEFAULT_VER_MAJOR,
+ unsigned char ver_miner=ROAST_WINDOWS_SOCKET_DEFAULT_VER_MINER)
+ {
+ if ( m_count == 0 )
+ {
+ startup();
+ }
+ m_count++;
}
- const ::WSADATA& get_wsadata(){ return m_wsaInfo; }
static void free()
{
- if ( ::WSACleanup() != 0 )
- throw socket_exception(::WSAGetLastError(), "roast::socket_cleanup::free() ::WSACleanup() function was error.");
+ m_count--;
+ if ( m_count == 0 )
+ {
+ cleanup();
+ }
}
+
+ static const ::WSADATA& get_wsadata(){ return m_wsaInfo; }
};
+
int socket_cleanup::m_count = 0;
}
}