CWorkerSocket.h
上传用户:hhs829
上传日期:2022-06-17
资源大小:586k
文件大小:2k
- //
- // CWorkerSocket.h
- // Created by Qiming Lu, 2002-02-25
- //
- #if !defined(__CWorkerSocket_h__)
- #define __CWorkerSocket_h__
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- // Error codes
- #define S_SOCKET_OK 0X10
- #define E_SOCKET_CLOSE 0X11
- #define E_SOCKET_FAIL 0X12
- #define E_SOCKET_NOT_READY 0x13
- // Message header
- typedef struct
- {
- unsigned int nMsgType:8; // Payload type
- unsigned int nDataSize:16; // Payload size
- } MSG_HEADER, *PMSG_HEADER;
- // Message
- #define RECV_EXIT 0x20 // Indicate stop receiving thread
- #define RECV_EXIT_REQUEST 0x21 // Request the remote to send some data
- //////////////////////////////////////////////////////////////////////////////
- class CWorkerSocket
- {
- public:
- CWorkerSocket();
- virtual ~CWorkerSocket();
- // Attributes
- protected:
- SOCKET m_hSocket;
- bool m_bReceiving;
- bool m_bSending;
- HANDLE m_hThrdFinish;
- HANDLE m_hSendFinish;
- public:
- bool Attach(SOCKET inSock);
- SOCKET Detach(void);
- int Send(char * inData, int inLen);
- int Receive(char * outBuf, int inLen);
- bool Connect(char * inTarget, int inPort);
- void Disconnect(void);
- // Receive functions
- bool StartReceiving(void);
- bool StopReceiving(void);
- virtual void ReceivingLoop(void);
- static UINT ReceivingThrd(void * pParam);
- // Send functions
- bool StartSending(void);
- bool StopSending(void);
- virtual void SendingLoop(void);
- static UINT SendingThrd(void * pParam);
- };
- #endif // !defined(__CWorkerSocket_h__)