- // NetException.h: interface for the CNetException class.
- //
- // Written by Marat Bedretdinov (maratb@hotmail.com)
- // Copyright (c) 2000.
- //
- // This code may be used in compiled form in any way you desire. This
- // file may be redistributed unmodified by any means PROVIDING it is
- // not sold for profit without the authors written consent, and
- // providing that this notice and the authors name is included.
- //
- // This file is provided "as is" with no expressed or implied warranty.
- // The author accepts no liability if it causes any damage whatsoever.
- // It's free - so you get what you pay for.//
- #if !defined(AFX_NETEXCEPTION_H__C8305B92_33D1_4983_B276_501A47CFDF21__INCLUDED_)
- #define AFX_NETEXCEPTION_H__C8305B92_33D1_4983_B276_501A47CFDF21__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #define ERR_NET_FAILED_INIT_WINSOCKDLL 107
- #define ERR_NET_FAILED_UNINIT_WINSOCKDLL 108
- #define ERR_NET_FAILED_CREATESOCKET 109
- #define ERR_NET_FAILED_CLOSESOCKET 110
- #define ERR_NET_FAILED_SHUTDOWNSOCKET 111
- #define ERR_NET_FAILED_BINDSVRADDR 112
- #define ERR_NET_FAILED_LISTENING 113
- #define ERR_NET_FAILED_CONNECTSVR 114
- #define ERR_NET_FAILED_ACCEPTSOCKET 115
- #define ERR_NET_FAILED_RECVEDDATA 116
- #define ERR_NET_FAILED_SENDEDDATA 117
- #define ERR_NET_FAILED_CREATEFILE 118
- #define ERR_NET_FAILED_WRITEFILE 119
- #define ERR_NET_ERROR_ASYNCSELECT 120
- #define ERR_NET_ERROR_CREATELOCALFILE 130
- extern long GetLastSocketError();
- extern const char* GetSocketErrorDescription(long);
- class CNetException
- {
- public:
- CNetException():m_nNetErr(0) {}
- CNetException(int nNetErr, const char* strFuncName, const char* strDescr = 0):
- m_nNetErr(nNetErr)
- {
- if (strFuncName) m_strFuncName = strFuncName;
- if (strDescr) m_strDescr = strDescr;
- }
- CNetException(const CNetException& x);
- virtual CNetException& operator=(const CNetException& x)
- {
- m_nNetErr = x.m_nNetErr;
- m_strFuncName = x.m_strFuncName;
- m_strDescr = x.m_strDescr;
- return *this;
- }
- virtual CNetException* clone() const { return new CNetException; }
- virtual ~CNetException();
- int GetErrCode() {return m_nNetErr;}
- const char* GetErrDescr() {return m_strDescr.c_str();}
- const char* GetErrFunc() {return m_strFuncName.c_str();}
- protected:
- int m_nNetErr;
- string m_strFuncName;
- string m_strDescr;
- };
- //
- class CNetSockException : public CNetException
- {
- public:
- CNetSockException(int nNetErr, int nSockErr, const char* strFuncName):
- CNetException(nNetErr, strFuncName),
- m_nSockErr(nSockErr) {}
- CNetSockException(const CNetSockException&);
- virtual CNetException& operator=(const CNetException& x)
- {
- CNetException::operator=(x);
- const CNetSockException& sx = static_cast<const CNetSockException&>(x);
- m_nSockErr = sx.m_nSockErr;
- return *this;
- }
- virtual CNetException* clone() const { return new CNetSockException; }
- virtual ~CNetSockException() {}
- int GetSockErrCode() {return m_nSockErr;}
- const char* GetSockErrDescr() {return GetSocketErrorDescription(m_nSockErr);}
- protected:
- CNetSockException() {}
- protected:
- int m_nSockErr;
- };
- #endif // !defined(AFX_NETEXCEPTION_H__C8305B92_33D1_4983_B276_501A47CFDF21__INCLUDED_)