123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #pragma once
- #include "CcosThread.h"
- #include "CcosLock.h"
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <pthread.h>
- #include <cstring>
- #include <cstdint>
- class P2P_Module_Base : public Ccos_Thread, public CcosLock
- {
- protected:
- char *m_pszMessageBuff;
- DWORD m_MessageBuffSize;
- PVOID m_pMainDevBus;
- char *m_pszIpAddress;
- char *m_pszLocalBusId;
- char *m_pszRemoteBusId;
- unsigned short m_Port;
- bool m_AsServer;
- int Socketfd;
- int m_SocketTarget;
- std::shared_ptr<LinuxEvent> m_ConnectionReady;
- //send block
- bool SendBlob(int&sck, const char *pMsg, const char *pBlock, DWORD size,bool Sync = false);
- bool ReadBlobSync(int&sck, char *pMsg, DWORD &MsgSize, char *pBlock, DWORD &size);
- bool ReadBlob(int&sck, char *pMsg, DWORD &MsgSize, char *pBlock, DWORD &size);
- public:
- P2P_Module_Base();
- ~P2P_Module_Base();
- //init
- void InitP2P(const char *pszIp, const char *pszLocalBusId, bool AsServer, PVOID pParent);
- //connect
- virtual bool ConnectP2P();
- //disconnect
- virtual void Disconnect();
- //check line
- virtual bool IsConnected();
- //do last quit
- virtual void Quit();
- bool IsTargetBusId(const char *pszTargetBusId);
- //callback
- virtual void OnBlob(char *pMsg, unsigned char *pData, DWORD size);
- virtual bool Exec();
- bool SendRaw(int&sck, const char *pData, DWORD size,bool Sync = false);
- bool ReadRawSync(int&sck, char *pszBuff, DWORD ExpectedSize);
- bool ReadRaw(int&sck, char *pszBuff, DWORD ExpectedSize);
-
- virtual bool SendBlob(const char *pMsg, const char *pBlock, DWORD size);
- //virtual bool ReadBlob(char *pMsg, DWORD &MsgSize, char *pBlock, DWORD &size);//¶ÔÍâ²»¹«¿ª£¬Ã»ÓÃ
- };
- class P2P_Module_Server : public P2P_Module_Base
- {
- DWORD m_HeartBeatTimeout;
- public:
- P2P_Module_Server();
- ~P2P_Module_Server();
- //connect
- virtual bool ConnectP2P();
- //disconnect
- virtual void Disconnect();
- virtual void Quit();
- virtual bool IsConnected();
- //callback,one way to client no receive from anyone
- //virtual void OnBlob(char *pMsg, char *pData, DWORD size);
- virtual bool Exec();
- int TryInit();
- int TryAccept();
- int TryCheckConnection();
- virtual bool SendBlob(const char *pMsg, const char *pBlock, DWORD size);
- };
- class P2P_Module_Client : public P2P_Module_Base
- {
- char *m_pszMsgBuff;
- unsigned char *m_pszBlockBuff;
- public:
- P2P_Module_Client();
- ~P2P_Module_Client();
- bool TryConnectServer();
- //connect
- virtual bool ConnectP2P();
- //disconnect
- virtual void Disconnect();
- //send block,one way to client no send to anyone
- //virtual bool SendBlob(char *pMsg, char *pBlock, DWORD size);
- //callback
- //virtual void OnBlob(char *pMsg, char *pData, DWORD size);
- virtual bool Exec();
- };
|