CConnection.h
资源名称:mysmtp2.rar [点击查看]
上传用户:young001
上传日期:2007-07-04
资源大小:33k
文件大小:1k
源码类别:
WEB邮件程序
开发平台:
Visual C++
- #ifndef CCONNECTION_H
- #define CCONNECTION_H
- #include <winsock.h>
- #include <stdio.h>
- #pragma comment(lib, "wsock32.lib") // search for wsock32 lib at compile time
- #pragma comment(lib, "mpr.lib") // search for mpr lib at compile time
- typedef void (*CALLBACKFUNC)(DWORD ptr);
- // another little class :)
- // (class itself is not thread-safe)
- class CError
- {
- long m_number;
- CError (long err);
- friend class CNetworking;
- friend class CConnection;
- friend class CSync;
- public:
- long GetErrorString (char* str, long len);
- };
- // class definition for CConnection
- // this class is thread-safe!
- // access to Tag is NOT synchronized!
- class CConnection
- {
- // used to cache the received data
- // this class is thread-safe!
- static long m_count;
- SOCKET m_socket;
- sockaddr_in m_addr;
- CError m_lasterror;
- // allow CNetworking to do stuff with this class
- public:
- void GetLocalIP(CString &sIP);
- void SetLastError (long err);
- BOOL HasConnectionDropped(void);
- CConnection ();
- CConnection (const char* host, unsigned short port);
- ~CConnection ();
- bool Connect (const char* host, unsigned short port);
- void Disconnect ();
- bool PeerInfo (char* host, int host_len, unsigned int* port);
- int Send (const char* buffer, int bufferlen);
- int Receive (char* buffer, int bufferlen);
- bool IsConnected ();
- void GetLastError (char* str, long len);
- DWORD Tag;
- };
- #endif