Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
SmartWSA.cpp
Package: popmail.zip [view]
Upload User: liuzhunlcd
Upload Date: 2007-01-12
Package Size: 54k
Code Size: 2k
Category:
Email Client
Development Platform:
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;
- }