From 7c5e63e1a9a9871bd1b8b44d9cd39c013d78a74f Mon Sep 17 00:00:00 2001 From: Myun2 Date: Mon, 21 May 2012 19:03:34 +0900 Subject: [PATCH] =?utf8?q?socket=5Fstartup.hpp=20=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/windows/socket_impl.hpp | 2 + roast/include/roast/windows/socket_startup.hpp | 67 ++++++++------------------ 2 files changed, 22 insertions(+), 47 deletions(-) diff --git a/roast/include/roast/windows/socket_impl.hpp b/roast/include/roast/windows/socket_impl.hpp index 9765a98a..d34ed8a4 100644 --- a/roast/include/roast/windows/socket_impl.hpp +++ b/roast/include/roast/windows/socket_impl.hpp @@ -13,6 +13,8 @@ #include #pragma comment(lib, "ws2_32.lib") +#include "roast/windows/socket_startup.hpp" + namespace roast { namespace windows diff --git a/roast/include/roast/windows/socket_startup.hpp b/roast/include/roast/windows/socket_startup.hpp index e95bd124..7046b336 100644 --- a/roast/include/roast/windows/socket_startup.hpp +++ b/roast/include/roast/windows/socket_startup.hpp @@ -2,70 +2,43 @@ /* */ -#ifndef __SFJP_ROAST__windows__socket_sub_HPP__ -#define __SFJP_ROAST__windows__socket_sub_HPP__ +#ifndef __SFJP_ROAST__windows__socket_startup_HPP__ +#define __SFJP_ROAST__windows__socket_startup_HPP__ -#define ROAST_WINDOWS_SOCKET_DEFAULT_VER_MAJOR (2) -#define ROAST_WINDOWS_SOCKET_DEFAULT_VER_MINER (0) - -////////////////////////////////////////////////// +#include +#pragma comment(lib, "ws2_32.lib") namespace roast { namespace windows { - class socket_cleanup + ////////////////////////////////////////////////////////////////////////////////// + + class socket_startup { - private: - static ::WSADATA m_wsaInfo; - static int m_count; + public: + ::WSADATA wsaInfo; - static void startup( - unsigned char ver_major=ROAST_WINDOWS_SOCKET_DEFAULT_VER_MAJOR, - unsigned char ver_miner=ROAST_WINDOWS_SOCKET_DEFAULT_VER_MINER) + socket_startup() { - ZeroMemory(&m_wsaInfo,sizeof(m_wsaInfo)); - - WORD wVersionRequested = MAKEWORD(ver_major, ver_miner); + ZeroMemory(&wsaInfo,sizeof(wsaInfo)); + WORD wVersionRequested = MAKEWORD(2, 0); // Use the Winsock 2.0 - if ( ::WSAStartup(wVersionRequested, &m_wsaInfo) != 0 ) - throw socket_exception(::WSAGetLastError(), "roast::socket_cleanup::add() ::WSAStartup() function was error."); + if ( ::WSAStartup(wVersionRequested, &wsaInfo) != 0 ) + throw socket_exception(::WSAGetLastError(), "roast::windows::socket_startup() ::WSAStartup() function was error."); } - static void cleanup() + virtual ~socket_startup() { if ( ::WSACleanup() != 0 ) - throw socket_exception(::WSAGetLastError(), "roast::socket_cleanup::free() ::WSACleanup() function was error."); + throw socket_exception(::WSAGetLastError(), "roast::windows::~socket_startup() ::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++; - } - - static void del() - { - m_count--; - if ( m_count == 0 ) - { - cleanup(); - } - } - - static const ::WSADATA& get_wsadata(){ return m_wsaInfo; } }; - // Static Variables - ::WSADATA socket_cleanup::m_wsaInfo; - int socket_cleanup::m_count = 0; + static socket_startup _socket_startup; + + ////////////////////////////////////////////////////////////////////////////////// } } -#endif//__SFJP_ROAST__windows__socket_sub_HPP__ +#endif//__SFJP_ROAST__windows__socket_startup_HPP__ -- 2.11.0