Add thread.
This commit is contained in:
@@ -10,7 +10,32 @@
|
||||
#include <afxwin.h>
|
||||
#include <afxcmn.h>
|
||||
#include <Winsock2.h>
|
||||
#define WM_SOCKET WM_USER + 0x1
|
||||
#define WM_SOCKET WM_USER + 0x060
|
||||
#define WM_TCPIP_RECV_DATA WM_USER + 0x061
|
||||
|
||||
#define lChannelSize 2
|
||||
#define CH_SEND 0
|
||||
#define CH_RECV 1
|
||||
|
||||
#define TCPIP_MAX_BUFF_SIZE 1024
|
||||
#define TCPIP_MAX_DAT_SIZE 1024
|
||||
|
||||
#define TCPIP_THREAD_RUNNING 0
|
||||
#define TCPIP_THREAD_PAUSED 1
|
||||
#define TCPIP_THREAD_EXIT -1
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
enum TCPIP_CMD
|
||||
{
|
||||
TCPIP_CMD_NONE=0,
|
||||
TCPIP_CMD_HANDSHAKING,
|
||||
TCPIP_CMD_READ_DATA,
|
||||
TCPIP_CMD_WRITE_DATA,
|
||||
|
||||
TCPIP_CMD_TATAL
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TCPIP_CONNECT_OK=0,
|
||||
@@ -20,8 +45,38 @@ typedef enum {
|
||||
TCPIP_INVAILD_IP_ADDRESS,
|
||||
TCPIP_INVAILD_PORT_NUMBER,
|
||||
TCPIP_CONNECT_SERVER_FAILED,
|
||||
} TCPIP_RETURN_CODE;
|
||||
TCPIP_CONNECT_STATUS_UNKNOWN
|
||||
|
||||
} TCPIP_RETURN_CODE;
|
||||
//======================
|
||||
struct struct_so7_tcpip_buff
|
||||
{
|
||||
BYTE _save_send_cmd;
|
||||
BYTE _save_send_cmd0;
|
||||
BYTE _save_send_cmd1;
|
||||
BYTE _save_send_cmd2;
|
||||
char *_buffer; // MAX_BUFF_SIZE
|
||||
int _size;
|
||||
int _CompletedSize;
|
||||
BOOL _hProtoPending;
|
||||
HANDLE _event;
|
||||
};
|
||||
struct struct_so7_tcpip_data
|
||||
{ // g_machine structure
|
||||
struct s_recv_data
|
||||
{
|
||||
int _type;
|
||||
int _DataSize;
|
||||
double *_dbBuff;
|
||||
} s_recv_data;
|
||||
struct s_status
|
||||
{
|
||||
TCPIP_RETURN_CODE _SendReturnCode;
|
||||
TCPIP_RETURN_CODE _RecvReturnCode;
|
||||
bool _handshaking;
|
||||
} s_status;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
//======================================================================================
|
||||
class CSo7_TCPIP
|
||||
{
|
||||
@@ -29,24 +84,27 @@ public:
|
||||
CSo7_TCPIP();
|
||||
virtual ~CSo7_TCPIP();
|
||||
|
||||
static struct_so7_tcpip_buff m_TCPIPBuf[lChannelSize];
|
||||
static struct_so7_tcpip_data m_TCPIPData;
|
||||
|
||||
static unsigned __stdcall m_Thread(LPVOID pThis) ;
|
||||
static HANDLE m_Thread_Id;
|
||||
static HANDLE m_Thread_Mutex;
|
||||
static int m_Thread_State;
|
||||
|
||||
TCPIP_RETURN_CODE Connect(const HWND& _hWnd,const in_addr& _IPAddress,const u_short& _nPortNumber);
|
||||
TCPIP_RETURN_CODE Send(int _Addr,int _Data);
|
||||
TCPIP_RETURN_CODE Recv(int _Addr,int& _Data,bool _bWait);
|
||||
TCPIP_RETURN_CODE DisConnect();
|
||||
TCPIP_RETURN_CODE GetHostIPAddr(in_addr& _IPAddress);
|
||||
TCPIP_RETURN_CODE Handshaking();
|
||||
|
||||
TCPIP_RETURN_CODE Handshaking();
|
||||
|
||||
LRESULT OnSocket(WPARAM wParam, LPARAM lParam);
|
||||
private:
|
||||
private:
|
||||
HWND m_hMsgWnd;
|
||||
|
||||
char *m_ReceiveBuf;
|
||||
char *m_SendBuf;
|
||||
double *m_dReceiveDBuf;
|
||||
int m_iReceiveDBufSize;
|
||||
int m_iBytesToReceive,m_iBytesReceived;
|
||||
int m_iBytesToSend,m_iBytesSent;
|
||||
static int m_iReceiveMaxBufSize;
|
||||
static int m_iSendMaxBufSize;
|
||||
|
||||
@@ -55,9 +113,14 @@ private:
|
||||
static in_addr m_ClientIPAddress;
|
||||
static u_short m_iServerPortNumber;
|
||||
|
||||
TCPIP_RETURN_CODE SendBuffer();
|
||||
void SendBuffer();
|
||||
void m_ClearSendBuf();
|
||||
|
||||
void Create_Thread();
|
||||
void Exit_Thread();
|
||||
void _do_single_threaded_tcpip_comm(bool _bWaitForRsponse=false);
|
||||
|
||||
|
||||
int Init_Winsock();
|
||||
void m_ProcessSocketWriteEvent();
|
||||
void m_ProcessSocketReadEvent(SOCKET s);
|
||||
|
||||
Reference in New Issue
Block a user