📄 communicate.h
字号:
// YsCommunicate.h: interface for the YsCommunicate class./////////////////////////////////////////////////////////////////////////** * * 文 件 名 : YsCommunicate.h * 创建日期 : 2006-09-10 * 作 者 : 邵凯田(skt001@163.com) * 修改日期 : $Date: 2006-10-27$ * 当前版本 : $Revision: $ * 功能描述 : 通迅类,可以作CLIENT或SERVER,作SERVER时,beginComm后使用getPeerConnection取活动连接 * 修改记录 : * $Log: $ **/#if !defined(AFX_YsCommunicate_H__C04C800E_6954_4A62_8B03_CA126935E641__INCLUDED_)#define AFX_YsCommunicate_H__C04C800E_6954_4A62_8B03_CA126935E641__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#include "YsLock.h"#include "YsSocket.h"#include "YsList.h"#ifndef _DEBUG#define _DEBUG#endif#ifdef WIN32 #pragma pack(4) #define WIN32_LEAN_AND_MEAN //#include <windows.h> #include <locale.h> #include <string.h> #include <time.h> /* timespec{} for pselect() */ #include <stdio.h> #include <iostream> #include <fstream> #include <process.h>//for thread#else #include <stdlib.h> #include <ctype.h> #include <fcntl.h> /* for nonblocking */ #include <signal.h> #include <signal.h> //#include <varargs.h> //#include <stdarg.h> #include <execinfo.h> #include <unistd.h> #include <netdb.h> #include <langinfo.h> #include <pthread.h> #include <sys/ioctl.h> #include <sys/socket.h> /* basic socket definitions */ #include <sys/time.h> /* timeval{} for select() */ #include <sys/stat.h> /* for S_xxx file mode constants */ #include <sys/uio.h> /* for iovec{} and readv/writev */ #include <sys/wait.h> #include <sys/un.h> /* for Unix domain sockets */ #include <sys/sem.h> #include <semaphore.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <sys/shm.h> #include <sys/mman.h> #include <sys/wait.h> #include <linux/kernel.h> #include <linux/ext2_fs.h> #include <netinet/in.h> /* sockaddr_in{} and other Internet defns */ #include <arpa/inet.h> /* inet(3) functions */#endif#include <stdio.h> #include <stdlib.h> #ifndef WORD#define WORD short#endif#include <string>using namespace std;class YsCommunicate;typedef YsCommunicate Communicate;class YsCommunicate : public YsSocket{public: enum Status { WORKING, ERROR }; enum CommType { /*NIL=4, NET=3, COM=0, */ CLIENT=1, SERVER=2, UDPCLIENT=11, UDPSERVER=12 ///@todo udp,udp_broadcast,udp_multicast };private: struct stuThreadSocketLsnParm { YsCommunicate *pListenSocket; CYsPtrList<YsCommunicate>* pClientList; };public: YsCommunicate(); virtual ~YsCommunicate(); Status getStat(); ///peer in details,for stream/datagram socket,return "[host]:[port]",for com,return "" string peerName(); ///million-seconds int timeout() {return m_iTimeout;}; void timeout(int val) {m_iTimeout=val;}; bool beginComm(CommType type,string addr,WORD port); //取跟此服务器连接的服务SOCKET,addr表示想要取的对方IP,当为空串时表示不关心对方IP YsCommunicate* getPeerConnection(string addr); ///peer in details,for stream/datagram socket,return "[host]:[port]",for com,return "" ///million-secondsprotected: bool beginCommClt(string addr,WORD port); bool beginCommSvr(string addr,WORD port); #ifdef WIN32 static DWORD WINAPI ThreadListenPort(void * lp); #else static void* ThreadListenPort(void * lp); #endifprivate: int m_iTimeout; CYsPtrList<YsCommunicate> m_ClientList;//连上当前服务器的客户端连接列表 stuThreadSocketLsnParm m_LsnParam; YsLock m_Lock; string m_sPeerName;#ifdef WIN32 HANDLE m_hListen;//后台监听线程ID#else CLocalMutex m_Mutex; pthread_t m_hListen;//后台监听线程ID#endif};#endif // !defined(AFX_YsCommunicate_H__C04C800E_6954_4A62_8B03_CA126935E641__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -