55 lines
1002 B
C
55 lines
1002 B
C
|
#pragma once
|
|||
|
#define WIN32_LEAN_AND_MEAN
|
|||
|
|
|||
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
#include <Windows.h>
|
|||
|
#include <WinSock2.h>
|
|||
|
#include <mswsock.h>
|
|||
|
#include <map>
|
|||
|
#include <string>
|
|||
|
#include <list>
|
|||
|
#include <mutex>
|
|||
|
|
|||
|
#pragma comment(lib, "ws2_32.lib")
|
|||
|
#pragma comment(lib, "Mswsock.lib")
|
|||
|
|
|||
|
class SocketS
|
|||
|
{
|
|||
|
public:
|
|||
|
struct msgInfo
|
|||
|
{
|
|||
|
int index;
|
|||
|
int len = 0;
|
|||
|
char buf[1025] = { 0 };
|
|||
|
};
|
|||
|
|
|||
|
private:
|
|||
|
struct clienInfo
|
|||
|
{
|
|||
|
SOCKET c_Sock;
|
|||
|
OVERLAPPED c_Olp;
|
|||
|
char c_strRecv[1024];
|
|||
|
};
|
|||
|
|
|||
|
BOOL g_flag = TRUE; //״̬
|
|||
|
HANDLE hPort = NULL; //<2F><><EFBFBD>ɶ˿ھ<CBBF><DABE><EFBFBD>
|
|||
|
HANDLE* pThread = NULL; //<2F>߳̾<DFB3><CCBE><EFBFBD>
|
|||
|
int g_count = 0; //<2F><>ǰ<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>ID
|
|||
|
std::map<int, clienInfo>ClienMap; //<2F><><EFBFBD>пͻ<D0BF><CDBB><EFBFBD>
|
|||
|
|
|||
|
std::mutex msgLock; //<2F><>Ϣ<EFBFBD><CFA2>
|
|||
|
std::list<msgInfo*>msgList; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
static DWORD WINAPI ThreadProc(LPVOID lpParameter); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
|||
|
|
|||
|
public:
|
|||
|
SocketS();
|
|||
|
int PostAccept(void);
|
|||
|
int PostRecv(int index);
|
|||
|
int PostSend(int index, const char* buf, int len);
|
|||
|
BOOL Creat(int Prot);
|
|||
|
void Clear();
|
|||
|
msgInfo* GetMsg();
|
|||
|
};
|
|||
|
|