SmartWSA.cpp
资源名称:popmail.zip [点击查看]
上传用户:liuzhunlcd
上传日期:2007-01-12
资源大小:54k
文件大小:2k
源码类别:
Email客户端
开发平台:
Visual C++
- // SmartWSA.cpp: implementation of the CSmartWSA class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include <wtypes.h>
- #include <iostream.h>
- #include "SmartWSA.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- //FD_SETSIZE=128
- CSmartWSA::CSmartWSA()
- {
- m_blIsInitialized = false;
- Startup();
- }
- CSmartWSA::~CSmartWSA()
- {
- Cleanup();
- }
- //-------------------------------------------------------------------
- // Startup()
- //-------------------------------------------------------------------
- bool CSmartWSA::Startup()
- {
- WORD wVersionRequested;
- WSADATA wsaData;
- INT iErr = 0;
- if(IsInitialized())
- return true;
- wVersionRequested = MAKEWORD(SMARTWSA_VERSION_HI, SMARTWSA_VERSION_LOW);
- iErr = WSAStartup(wVersionRequested, &wsaData);
- if(iErr != 0)
- {
- // Tell the user that we could not find a usable WinSock DLL
- //g_cLog << "WSAStartup() failed with code " << iErr << endl;
- return false;
- }
- // Confirm that the WinSock DLL supports 2.2.
- // Note that if the DLL supports versions greater
- // than 2.2 in addition to 2.2, it will still return
- // 2.2 in wVersion since that is the version we requested
- if(LOBYTE(wsaData.wVersion) != SMARTWSA_VERSION_LOW || HIBYTE(wsaData.wVersion) != SMARTWSA_VERSION_HI )
- {
- // Tell the user that we could not find a usable WinSock DLL.
- //g_cLog << "could not find a usable WinSock DLL, only next version may be used: " << LOBYTE(wsaData.wVersion)
- // << "." << HIBYTE(wsaData.wVersion) << endl;
- Cleanup();
- return false;
- }
- // The WinSock DLL is acceptable. Proceed.
- m_blIsInitialized = true;
- return true;
- }
- //-------------------------------------------------------------------
- // Cleanup()
- //-------------------------------------------------------------------
- bool CSmartWSA::Cleanup()
- {
- if(IsInitialized() == false)
- return true;
- if(WSACleanup() == SOCKET_ERROR)
- {
- INT iErr = WSAGetLastError();
- //g_cLog << "WSACleanup() failed with code " << iErr << endl;
- return false;
- }
- m_blIsInitialized = false;
- return true;
- }
- //-------------------------------------------------------------------
- // IsInitialized()
- //-------------------------------------------------------------------
- bool CSmartWSA::IsInitialized() const
- {
- return m_blIsInitialized;
- }