This commit is contained in:
aixianling
2025-01-09 17:45:40 +08:00
commit 5c9f1dae4a
3482 changed files with 1146531 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
#ifndef _ASYN_CLIENT_SOCKET_H_
#define _ASYN_CLIENT_SOCKET_H_
using namespace tick64;
using namespace container;
using namespace lock;
class AsynClientSocket :
public AsynWorkSocket
{
public:
typedef AsynWorkSocket Inherited;
public:
AsynClientSocket(const char* name);
virtual ~AsynClientSocket();
inline const char* GetClientName()
{
return client_name_;
};
inline const char* GetHost()
{
return host_;
}
void SetHost(const char* sHost);
inline int GetPort()
{
return port_;
}
void SetPort(const int nPort);
bool Startup();
void Stop();
//unsigned long GetThreadId()
//{
// return thread_id_;
//}
protected:
virtual void OnWorkThreadStart();
virtual void OnWorkThreadStop();
virtual int GetLocalServerType() = 0;
virtual const char* GetLocalServerName() = 0;
virtual int GetLocalServerIndex();
void SendRegisteClient();
protected:
void SetClientName(const char* sClientName);
bool ConnectToServer();
void SingleRun();
protected:
void Connected();
void Disconnected();
void SocketError(int errorCode);
private:
#ifdef _MSC_VER
HANDLE handle_; //<2F><><EFBFBD><EFBFBD><EFBFBD>߳̾<DFB3><CCBE><EFBFBD>
HANDLE recv_handle_;
unsigned long thread_id_; //<2F>߳<EFBFBD>ID
unsigned long recv_thread_id_; //<2F>߳<EFBFBD>ID
static void STDCALL Work_R(AsynClientSocket* client);
static void STDCALL Recv_R(AsynClientSocket* client);
#else
pthread_t thread_id_;
pthread_t recv_thread_id_;
static void* Work_R(void* client);
static void* Recv_R(void* client);
#endif
bool stoped_; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ϊֹͣ
bool recv_stoped_; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ϊֹͣ
bool exit_;
bool recv_exit_;
char host_[256]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
u_long addr_;
int port_; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
char client_name_[256]; //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
time_t reconn_t_; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
};
#endif