From 47fc18035b57a9478df3fa9020acd8c7b7cd1e4e Mon Sep 17 00:00:00 2001 From: thinking Date: Mon, 19 Mar 2018 00:26:26 +0800 Subject: [PATCH 01/10] asynio interface up --- asynio/asynioimpl.cpp | 18 ++++----- asynio/asynioimpl.h | 12 +++--- asynio/ioeventloop.h | 29 ++++++++++++++ asynio/iostreambase.h | 4 +- asynio/iotcpbase.h | 30 +++----------- bin/Debug/mainmoduleconfig.json | 66 +++++++++++++++---------------- extensions/include/io/iasynio.h | 59 ++++++++++++++------------- include/util/core.hpp | 3 +- include/util/filedef.hpp | 13 ++++++ include/util/locksection.hpp | 15 +++++++ include/util/socketdef.hpp | 29 ++++++++------ infoanalysis/infoanalysisimpl.cpp | 5 +-- mempool/Debug/mempool.log | 7 +++- sshchannel/sshchannelimpl.cpp | 2 +- 14 files changed, 171 insertions(+), 121 deletions(-) create mode 100644 include/util/filedef.hpp diff --git a/asynio/asynioimpl.cpp b/asynio/asynioimpl.cpp index 45934649..ef57cf4a 100644 --- a/asynio/asynioimpl.cpp +++ b/asynio/asynioimpl.cpp @@ -43,31 +43,31 @@ std_method_impl CAsynIoImpl::Stop() HRESULT hr = S_OK; return hr; } -std_method_impl CAsynIoImpl::CreateReadFile(IModuleBase** pReadFile) +std_method_impl CAsynIoImpl::CreateReadFile(IReadFile** pReadFile) { HRESULT hr = S_OK; IReadFile* pObject = NULL; pObject = new CFileReadImpl; pObject->AddRef(); - *pReadFile = reinterpret_cast(pObject); + *pReadFile = reinterpret_cast(pObject); return hr; } -std_method_impl CAsynIoImpl::CreateWriteFile(IModuleBase** pWriteFile) +std_method_impl CAsynIoImpl::CreateWriteFile(IWriteFile** pWriteFile) { HRESULT hr = S_OK; IWriteFile* pObject = NULL; pObject = new CFileWriteImpl; pObject->AddRef(); - *pWriteFile = reinterpret_cast(pObject); + *pWriteFile = reinterpret_cast(pObject); return hr; } -std_method_impl CAsynIoImpl::CreateAsynTcpSocket(IModuleBase** pAsynTcpSocket) +std_method_impl CAsynIoImpl::CreateAsynTcpSocket(IAsynTcpSocket** pAsynTcpSocket) { HRESULT hr = S_OK; return hr; } -std_method_impl CAsynIoImpl::CreateTcpSocket(IModuleBase** pTcpSocket) +std_method_impl CAsynIoImpl::CreateTcpSocket(ITcpSocket** pTcpSocket) { HRESULT hr = S_OK; @@ -75,16 +75,16 @@ std_method_impl CAsynIoImpl::CreateTcpSocket(IModuleBase** pTcpSocket) pObject = new CTcpSocketImpl; pObject->AddRef(); - *pTcpSocket = reinterpret_cast(pObject); + *pTcpSocket = reinterpret_cast(pObject); return hr; } -std_method_impl CAsynIoImpl::CreateAsynUdpSocket(IModuleBase** pAsynUdpSocket) +std_method_impl CAsynIoImpl::CreateAsynUdpSocket(IAsynUdpSocket** pAsynUdpSocket) { HRESULT hr = S_OK; return hr; } -std_method_impl CAsynIoImpl::CreateUdpSocket(IModuleBase** pUdpSocket) +std_method_impl CAsynIoImpl::CreateUdpSocket(IUdpSocket** pUdpSocket) { HRESULT hr = S_OK; return hr; diff --git a/asynio/asynioimpl.h b/asynio/asynioimpl.h index 3e2d41d0..55dabcf6 100644 --- a/asynio/asynioimpl.h +++ b/asynio/asynioimpl.h @@ -34,12 +34,12 @@ public: ////////////////////////////////////////////////////////////////////////// - std_method(CreateReadFile)(IModuleBase** pReadFile); - std_method(CreateWriteFile)(IModuleBase** pWriteFile); - std_method(CreateAsynTcpSocket)(IModuleBase** pAsynTcpSocket); - std_method(CreateTcpSocket)(IModuleBase** pTcpSocket); - std_method(CreateAsynUdpSocket)(IModuleBase** pAsynUdpSocket); - std_method(CreateUdpSocket)(IModuleBase** pUdpSocket); + std_method(CreateReadFile)(IReadFile** pReadFile); + std_method(CreateWriteFile)(IWriteFile** pWriteFile); + std_method(CreateAsynTcpSocket)(IAsynTcpSocket** pAsynTcpSocket); + std_method(CreateTcpSocket)(ITcpSocket** pTcpSocket); + std_method(CreateAsynUdpSocket)(IAsynUdpSocket** pAsynUdpSocket); + std_method(CreateUdpSocket)(IUdpSocket** pUdpSocket); std_method(DeleteIo)(IModuleBase* pAsynIo); private: diff --git a/asynio/ioeventloop.h b/asynio/ioeventloop.h index 679482d3..ce805bb0 100644 --- a/asynio/ioeventloop.h +++ b/asynio/ioeventloop.h @@ -46,6 +46,35 @@ protected: }; +class io_buff_t { +public: + io_buff_t() { + + } + virtual ~io_buff_t() { + + } + int MemAlloc(int size) { + buf.base= (char*)malloc(sizeof(char) * size + 1); + buf.len = size; + } + int MemRealloc(int size) { + buf.base = (char*)realloc(buf.base,sizeof(char) * size + 1); + buf.len = size; + } + int MemFree() { + free(buf.base); + } + operator void* () const { + return buf.base; + } + int len() { + return buf.len; + } +private: + uv_buf_t buf; +}; + #endif \ No newline at end of file diff --git a/asynio/iostreambase.h b/asynio/iostreambase.h index 3794c218..16bde82b 100644 --- a/asynio/iostreambase.h +++ b/asynio/iostreambase.h @@ -4,8 +4,7 @@ #include "ioeventloop.h" -class io_stream_t : public ioeventbase -{ +class io_stream_t : public ioeventbase { public: io_stream_t() { @@ -16,4 +15,5 @@ public: }; + #endif diff --git a/asynio/iotcpbase.h b/asynio/iotcpbase.h index e790ccd5..dd442d0a 100644 --- a/asynio/iotcpbase.h +++ b/asynio/iotcpbase.h @@ -3,42 +3,22 @@ #include "iostreambase.h" -class iotcpbase : public io_stream_t -{ + +class iotcpbase : public io_stream_t { public: iotcpbase() { tcphandler = NULL; - uv_tcp_init(GetEv(), tcphandler); } virtual ~iotcpbase() { } - int AattchToIo(SOCKET sock) { + int BindToIoEvent(SOCKET sock) { + tcphandler = (uv_tcp_t*)malloc(sizeof(uv_tcp_t)); + uv_tcp_init(GetEv(), tcphandler); return uv_tcp_open(tcphandler, sock); } private: uv_tcp_t *tcphandler; }; - -class io_tcp_s : public iotcpbase -{ -public: - io_tcp_s() { - - } - virtual ~io_tcp_s() { - - } -}; -class io_tcp_c : public iotcpbase -{ -public: - io_tcp_c() { - - } - virtual ~io_tcp_c() { - - } -}; #endif diff --git a/bin/Debug/mainmoduleconfig.json b/bin/Debug/mainmoduleconfig.json index 90d44516..0f86bee1 100644 --- a/bin/Debug/mainmoduleconfig.json +++ b/bin/Debug/mainmoduleconfig.json @@ -1,39 +1,39 @@ { "commodule":{ "basecom": [ - {"components_path":"infoanalysis","clsidinclude": - [ - { - "clsid":"{E2C3154C-AFC7-4875-8BCC-CB116CA0CF45}", - "name":"json", - "start":"2", - "ui":"0", - "param":"dateui2.res" - } - ] - }, - {"components_path":"asynio","clsidinclude": - [ - { - "clsid":"{B6DDB9B0-186F-4199-A0B3-7BA5026F5888}", - "name":"asynio", - "start":"3", - "ui":"0", - "param":"dateui2.res" - } - ] - }, - {"components_path":"maincom","clsidinclude": - [ - { - "clsid":"{764607A4-158C-4539-BD37-30B6983BE387}", - "name":"main", - "start":"20", - "ui":"0", - "param":"dateui2.res" - } - ] - } + {"components_path":"infoanalysis","clsidinclude": + [ + { + "clsid":"{E2C3154C-AFC7-4875-8BCC-CB116CA0CF45}", + "name":"json", + "start":"2", + "ui":"0", + "param":"dateui2.res" + } + ] + }, + {"components_path":"asynio","clsidinclude": + [ + { + "clsid":"{B6DDB9B0-186F-4199-A0B3-7BA5026F5888}", + "name":"asynio", + "start":"3", + "ui":"0", + "param":"dateui2.res" + } + ] + }, + {"components_path":"sshchannel","clsidinclude": + [ + { + "clsid":"{4A27FA11-BEA7-46E8-9F32-EC0C9F6E1A9E}", + "name":"sshchannel", + "start":"10", + "ui":"0", + "param":"dateui2.res" + } + ] + } ], "maincom": {"components_path":"comenv","clsidinclude": diff --git a/extensions/include/io/iasynio.h b/extensions/include/io/iasynio.h index 0fadf154..bc160091 100644 --- a/extensions/include/io/iasynio.h +++ b/extensions/include/io/iasynio.h @@ -4,7 +4,6 @@ interface IReadFile : public IModuleBase { - std_method(LoadFile)(const TCHAR* pszLoadFile, unsigned long ulwDesiredAccess, unsigned long ulShareMode, @@ -38,22 +37,13 @@ MD_DEFINE_IID(IWriteFile, "{6F7C433A-D7C5-4EFB-A525-701A675D7382}"); interface ISocket : public IModuleBase { - std_method(CreateSocket)() = 0; - std_method(Bind)(const char* addr, unsigned int uport) = 0; - std_method_(SOCKET,BindAccept)(const char* addr, unsigned int uport,int n) = 0; - std_method(CloseSocket)() = 0; - std_method_(ssize_t,Send)(const char* buf,size_t len,int flags) = 0; - std_method_(ssize_t,Recv)(char* addr,size_t len,int flags) = 0; - std_method_(SOCKET,GetSocket)() = 0; - std_method(SetReuseAddr)(bool bstart) = 0; - std_method(SetNoDelay)(bool bstart) = 0; - std_method(SetLinger)(bool bstart) = 0; - std_method(SetKeepalive)(bool bstart) = 0; - std_method(SetCork)(bool bstart) = 0; - std_method(SetNoSigPipe)(bool bstart) = 0; + std_method(CreateSocket)() = 0; + std_method(CloseSocket)() = 0; + std_method_(SOCKET, GetSocket)() = 0; + std_method_(ssize_t, Send)(const char* buf, size_t len, int flags) = 0; + std_method_(ssize_t, Recv)(char* addr, size_t len, int flags) = 0; }; - //#define SO_SNDBUF 0x1001 // send buffer size //#define SO_RCVBUF 0x1002 // receive buffer size //#define SO_SNDLOWAT 0x1003 // send low-water mark @@ -63,15 +53,20 @@ interface ISocket : public IModuleBase interface ITcpSocket : public ISocket { - - + std_method(Bind)(const char* addr, unsigned int uport) = 0; + std_method_(SOCKET, BindAccept)(const char* addr, unsigned int uport, int n) = 0; + std_method(SetReuseAddr)(bool bstart) = 0; + std_method(SetNoDelay)(bool bstart) = 0; + std_method(SetLinger)(bool bstart) = 0; + std_method(SetKeepalive)(bool bstart) = 0; + std_method(SetCork)(bool bstart) = 0; + std_method(SetNoSigPipe)(bool bstart) = 0; }; MD_DEFINE_IID(ITcpSocket, "{6F7C433A-D7C5-4EFB-A525-701A675D7388}"); interface IAsynTcpSocket : public ITcpSocket { - std_method(SetNonblock)(bool bstart) = 0; std_method(SendBufLen)(int size) = 0; std_method(RecvBufLen)(int size) = 0; @@ -79,24 +74,34 @@ interface IAsynTcpSocket : public ITcpSocket std_method(RecvTime)(int sec) = 0; std_method(SendLoWat)(int size) = 0; std_method(RecvLoWat)(int size) = 0; - }; MD_DEFINE_IID(IAsynTcpSocket, "{6F7C433A-D7C5-4EFB-A525-701A675D7389}"); +interface IUdpSocket : public ISocket +{ + +}; +MD_DEFINE_IID(IUdpSocket, "{011A712D-1CD0-4F01-B365-35CB79AABBC6}"); + +interface IAsynUdpSocket : public ISocket +{ + +}; +MD_DEFINE_IID(IAsynUdpSocket, "{AD708F28-58CB-46CE-A672-A16662944D8A}"); + interface IAsynIo : public IModuleBase { - std_method(CreateReadFile)(IModuleBase** pReadFile) = 0; - std_method(CreateWriteFile)(IModuleBase** pWriteFile) = 0; - std_method(CreateAsynTcpSocket)(IModuleBase** pAsynTcpSocket) = 0; - std_method(CreateTcpSocket)(IModuleBase** pTcpSocket) = 0; - std_method(CreateAsynUdpSocket)(IModuleBase** pAsynUdpSocket) = 0; - std_method(CreateUdpSocket)(IModuleBase** pUdpSocket) = 0; - - std_method(DeleteIo)(IModuleBase* pAsynIo) = 0; + std_method(CreateReadFile)(IReadFile** pReadFile) = 0; + std_method(CreateWriteFile)(IWriteFile** pWriteFile) = 0; + std_method(CreateAsynTcpSocket)(IAsynTcpSocket** pAsynTcpSocket) = 0; + std_method(CreateTcpSocket)(ITcpSocket** pTcpSocket) = 0; + std_method(CreateAsynUdpSocket)(IAsynUdpSocket** pAsynUdpSocket) = 0; + std_method(CreateUdpSocket)(IUdpSocket** pUdpSocket) = 0; + std_method(DeleteIo)(IModuleBase* pAsynIo) = 0; }; MD_DEFINE_IID(IAsynIo, "{91559897-31F2-46C1-85AB-1ED97D58EE7B}"); diff --git a/include/util/core.hpp b/include/util/core.hpp index 54c7d6c9..d8aac20d 100644 --- a/include/util/core.hpp +++ b/include/util/core.hpp @@ -77,7 +77,8 @@ #define byuint64 unsigned __int64 #define FMT_I64D "%I64d" #define FMT_I64U "%I64u" - + typedef SSIZE_T ssize_t; + #elif (TARGET_OS == OS_POSIX) #include #include diff --git a/include/util/filedef.hpp b/include/util/filedef.hpp new file mode 100644 index 00000000..8a5f4a29 --- /dev/null +++ b/include/util/filedef.hpp @@ -0,0 +1,13 @@ +#ifndef _FILEDEF_H_ +#define _FILEDEF_H_ + +#include + +#if (TARGET_OS == OS_WINDOWS) + typedef HANDLE os_fd_t; +#elif (TARGET_OS == OS_POSIX) + typedef int os_fd_t; +#endif + + +#endif diff --git a/include/util/locksection.hpp b/include/util/locksection.hpp index 15e26ce9..abfe9220 100644 --- a/include/util/locksection.hpp +++ b/include/util/locksection.hpp @@ -11,6 +11,21 @@ #endif +#if (TARGET_OS == OS_WINDOWS) + typedef HANDLE os_fd_t; + typedef int os_pid_t; + typedef HANDLE os_thread_t; + typedef HANDLE os_sem_t; + typedef CRITICAL_SECTION os_mutex_t; +#elif (TARGET_OS == OS_POSIX) + typedef int os_fd_t; + typedef pid_t os_pid_t; + typedef pthread_t os_thread_t; + typedef sem_t os_sem_t; + typedef pthread_mutex_t os_mutex_t; +#endif + + namespace util { diff --git a/include/util/socketdef.hpp b/include/util/socketdef.hpp index 445b2028..af86118e 100644 --- a/include/util/socketdef.hpp +++ b/include/util/socketdef.hpp @@ -1,13 +1,16 @@ -#ifndef _SOCKETDEF_H_ -#define _SOCKETDEF_H_ - - #if (TARGET_OS == OS_WINDOWS) - - typedef SSIZE_T ssize_t; - - #elif (TARGET_OS == OS_POSIX) - #define SOCKET int - #define INVALID_SOCKET -1 - #endif - -#endif \ No newline at end of file +#ifndef _SOCKETDEF_H_ +#define _SOCKETDEF_H_ + +#include + +#if (TARGET_OS == OS_WINDOWS) + typedef SSIZE_T ssize_t; + typedef SOCKET os_sock_t; + +#elif (TARGET_OS == OS_POSIX) + #define SOCKET int + #define INVALID_SOCKET -1 + typedef int os_sock_t; +#endif + +#endif diff --git a/infoanalysis/infoanalysisimpl.cpp b/infoanalysis/infoanalysisimpl.cpp index 3130984e..57e8d073 100644 --- a/infoanalysis/infoanalysisimpl.cpp +++ b/infoanalysis/infoanalysisimpl.cpp @@ -62,7 +62,6 @@ std_method_impl CInfoAnalysisImpl::NewLoadFileObject(const TCHAR* filepath, IMod retrtpv(ioNodeInfo, E_FAIL); CComLoader comLoader; _lComPtr pAsynIo = INULL; - IReadFile* pReadFile = NULL; if (m_pRot != INULL) @@ -72,7 +71,7 @@ std_method_impl CInfoAnalysisImpl::NewLoadFileObject(const TCHAR* filepath, IMod if (pAsynIo != NULL) { - pAsynIo->CreateReadFile((IModuleBase**)ioNodeInfo); + pAsynIo->CreateReadFile(&pReadFile); } else { @@ -101,7 +100,7 @@ std_method_impl CInfoAnalysisImpl::NewLoadFileObject(const TCHAR* filepath, IMod if (hr == S_OK) { - pAsynIo->CreateReadFile((IModuleBase**)&pReadFile); + pAsynIo->CreateReadFile(&pReadFile); } else { diff --git a/mempool/Debug/mempool.log b/mempool/Debug/mempool.log index 5f282702..45f727c3 100644 --- a/mempool/Debug/mempool.log +++ b/mempool/Debug/mempool.log @@ -1 +1,6 @@ - \ No newline at end of file + stdafx.cpp + dllmain.cpp + mempoolimpl.cpp +dllmain.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification + Creating library ..\lib\Debug\mempool.lib and object ..\lib\Debug\mempool.exp + mempool.vcxproj -> C:\workspace\lbyc\\bin\Debug\mempool.dll diff --git a/sshchannel/sshchannelimpl.cpp b/sshchannel/sshchannelimpl.cpp index 5c4dcd40..18356dc4 100644 --- a/sshchannel/sshchannelimpl.cpp +++ b/sshchannel/sshchannelimpl.cpp @@ -53,7 +53,7 @@ std_method_type_impl(sshid) CSshChannelImpl::CreateSshChannel() { retrtpv(m_pIAsynIo,E_FAIL) ITcpSocket* pSock = NULL; - HRESULT hr = m_pIAsynIo->CreateTcpSocket((IModuleBase**)&pSock); + HRESULT hr = m_pIAsynIo->CreateTcpSocket(&pSock); RFAILEDV(hr,-1) retrtpv(pSock,-1) pSock->CreateSocket(); -- Gitee From 881d8645d156335633ccb904a8f437500380ae9a Mon Sep 17 00:00:00 2001 From: thinking Date: Mon, 19 Mar 2018 00:28:17 +0800 Subject: [PATCH 02/10] del log --- mempool/Debug/mempool.log | 6 ------ mempool/Release/mempool.log | 1 - 2 files changed, 7 deletions(-) delete mode 100644 mempool/Debug/mempool.log delete mode 100644 mempool/Release/mempool.log diff --git a/mempool/Debug/mempool.log b/mempool/Debug/mempool.log deleted file mode 100644 index 45f727c3..00000000 --- a/mempool/Debug/mempool.log +++ /dev/null @@ -1,6 +0,0 @@ - stdafx.cpp - dllmain.cpp - mempoolimpl.cpp -dllmain.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification - Creating library ..\lib\Debug\mempool.lib and object ..\lib\Debug\mempool.exp - mempool.vcxproj -> C:\workspace\lbyc\\bin\Debug\mempool.dll diff --git a/mempool/Release/mempool.log b/mempool/Release/mempool.log deleted file mode 100644 index 5f282702..00000000 --- a/mempool/Release/mempool.log +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file -- Gitee From 8f2cc6c2b20198b980a3d08e7ec9aa69efbb6028 Mon Sep 17 00:00:00 2001 From: thinking Date: Wed, 21 Mar 2018 23:40:32 +0800 Subject: [PATCH 03/10] diff system --- CMakeLists.txt | 4 +- asynio/asynctcpsocketimpl.cpp | 155 +++++++++ asynio/asynctcpsocketimpl.h | 56 +++ asynio/asynio.vcxproj | 6 +- asynio/asynioimpl.cpp | 12 +- asynio/asynioimpl.h | 4 +- asynio/ioeventdef.h | 5 + asynio/ioeventloop.h | 22 +- asynio/iostreambase.h | 5 +- asynio/iotcpbase.cpp | 22 ++ asynio/iotcpbase.h | 25 +- asynio/tcpsocketimpl.cpp | 51 +-- asynio/tcpsocketimpl.h | 15 +- extensions/include/io/iasynio.h | 17 +- include/dlcom/byunknown.hpp | 8 +- include/dlcom/loadcom.hpp | 8 +- include/util/bits.hpp | 35 ++ include/util/calldll.hpp | 4 +- include/util/common.hpp | 124 +++++++ include/util/core.hpp | 597 ++------------------------------ include/util/locksection.hpp | 3 +- include/util/posix/osdef.h | 32 ++ include/util/posix/ossysdef.h | 250 +++++++++++++ include/util/singletion.hpp | 52 +++ include/util/socketdef.hpp | 2 +- include/util/targetos.hpp | 55 +++ include/util/unix/osdef.h | 47 +++ include/util/unix/ossysdef.h | 7 + include/util/util.h | 9 +- include/util/win/osdef.h | 20 ++ include/util/win/ossysdef.h | 7 + 31 files changed, 993 insertions(+), 666 deletions(-) create mode 100644 asynio/asynctcpsocketimpl.cpp create mode 100644 asynio/asynctcpsocketimpl.h create mode 100644 include/util/bits.hpp create mode 100644 include/util/common.hpp create mode 100644 include/util/posix/osdef.h create mode 100644 include/util/posix/ossysdef.h create mode 100644 include/util/singletion.hpp create mode 100644 include/util/targetos.hpp create mode 100644 include/util/unix/osdef.h create mode 100644 include/util/unix/ossysdef.h create mode 100644 include/util/win/osdef.h create mode 100644 include/util/win/ossysdef.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f3cf98f8..ea478163 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,9 +39,9 @@ message("-- lbycom Compile = ${CMAKE_BUILD_TYPE}") add_subdirectory(main) add_subdirectory(comenv) add_subdirectory(infoanalysis) -add_subdirectory(asynio) +#add_subdirectory(asynio) add_subdirectory(sshchannel) -add_subdirectory(adapterjs) +#add_subdirectory(adapterjs) #add_subdirectory(adapterlua) #add_subdirectory(adapterpy) #add_subdirectory(mempool) diff --git a/asynio/asynctcpsocketimpl.cpp b/asynio/asynctcpsocketimpl.cpp new file mode 100644 index 00000000..3db949b1 --- /dev/null +++ b/asynio/asynctcpsocketimpl.cpp @@ -0,0 +1,155 @@ +#include "asynctcpsocketimpl.h" + +CAsyncTcpSocketImpl::CAsyncTcpSocketImpl() +{ + m_socketFd = -1; +} +CAsyncTcpSocketImpl::~CAsyncTcpSocketImpl() +{ + +} +////////////////////////////////////////////////////////////////////////// +std_method_impl CAsyncTcpSocketImpl::CreateSocket() +{ + HRESULT hr = S_OK; + + m_socketFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (m_socketFd == INVALID_SOCKET) { + return E_FAIL; + } + + return hr; +} + +std_method_impl CAsyncTcpSocketImpl::CloseSocket() +{ + HRESULT hr = S_OK; + + return hr; +} +std_method_type_impl(os_sock_t) CAsyncTcpSocketImpl::GetSocket() +{ + return m_socketFd; +} +std_method_type_impl(ssize_t) CAsyncTcpSocketImpl::Send(const char* buf,size_t len,int flags) +{ + return -1; +} +std_method_type_impl(ssize_t) CAsyncTcpSocketImpl::Recv(char* addr,size_t len,int flags) +{ + return -1; +} + + +std_method_impl CAsyncTcpSocketImpl::Bind(const char* addr, unsigned int uport) +{ + HRESULT hr = S_OK; + + retrtpv(addr, E_FAIL) + retrtpv(uport, E_FAIL) + + struct sockaddr_in sin; + sin.sin_family = AF_INET; + if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(addr))) { + return E_FAIL; + } + sin.sin_port = htons(uport); + if (connect(m_socketFd, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) { + return E_FAIL; + } + + return hr; +} +std_method_type_impl(os_sock_t) CAsyncTcpSocketImpl::BindAccept(const char* addr, unsigned int uport, int n) +{ + return -1; +} +std_method_impl CAsyncTcpSocketImpl::SetReuseAddr(bool bstart) +{ + HRESULT hr = S_OK; + + return hr; +} +std_method_impl CAsyncTcpSocketImpl::SetNoDelay(bool bstart) +{ + HRESULT hr = S_OK; + + return hr; +} +std_method_impl CAsyncTcpSocketImpl::SetLinger(bool bstart) +{ + HRESULT hr = S_OK; + + return hr; +} +std_method_impl CAsyncTcpSocketImpl::SetKeepalive(bool bstart) +{ + HRESULT hr = S_OK; + + return hr; +} +std_method_impl CAsyncTcpSocketImpl::SetCork(bool bstart) +{ + HRESULT hr = S_OK; + int set = 0; + set = (bstart == true? 1 : 0); + +#if (TARGET_OS != OS_WINDOWS) + setsockopt(m_socketFd, SOL_TCP, TCP_CORK, (void *)&set, sizeof(int)); +#endif + + return hr; +} +std_method_impl CAsyncTcpSocketImpl::SetNoSigPipe(bool bstart) +{ + + HRESULT hr = S_OK; + + int set = 0; + set = (bstart == true? 1 : 0); + + //unix no found MSG_NOSIGNAL, but have SO_NOSIGPIPE + +#if (TARGET_OS != OS_WINDOWS) + +#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) + #define MSG_NOSIGNAL SO_NOSIGPIPE +#endif + + setsockopt(m_socketFd, SOL_SOCKET, MSG_NOSIGNAL, (void *)&set, sizeof(int)); + +#endif + + return hr; +} +std_method_impl CAsyncTcpSocketImpl::SetNonblock(bool bstart) +{ + return S_OK; +} +std_method_impl CAsyncTcpSocketImpl::SendBufLen(int size) +{ + return S_OK; +} +std_method_impl CAsyncTcpSocketImpl::RecvBufLen(int size) +{ + return S_OK; +} +std_method_impl CAsyncTcpSocketImpl::SendTime(int sec) +{ + return S_OK; +} +std_method_impl CAsyncTcpSocketImpl::RecvTime(int sec) +{ + return S_OK; +} +std_method_impl CAsyncTcpSocketImpl::SendLoWat(int size) +{ + return S_OK; +} +std_method_impl CAsyncTcpSocketImpl::RecvLoWat(int size) +{ + return S_OK; +} + + diff --git a/asynio/asynctcpsocketimpl.h b/asynio/asynctcpsocketimpl.h new file mode 100644 index 00000000..5a3e010f --- /dev/null +++ b/asynio/asynctcpsocketimpl.h @@ -0,0 +1,56 @@ +#ifndef _ASYNCTCPSOCKIMPL_H_ +#define _ASYNCTCPSOCKIMPL_H_ + +#include "stdafx.h" +#include +#include "iotcpbase.h" + +class CAsyncTcpSocketImpl : public IAsyncTcpSocket, + public CUnknownImp + +{ +public: + CAsyncTcpSocketImpl(void); + virtual ~CAsyncTcpSocketImpl(void); + UNKNOWN_IMP1(IAsyncTcpSocket); + ////////////////////////////////////////////////////////////////////////// + //ISocket + std_method(CreateSocket)(); + std_method(CloseSocket)(); + std_method_(ssize_t,Send)(const char* buf,size_t len,int flags); + std_method_(ssize_t,Recv)(char* addr,size_t len,int flags); + std_method_(os_sock_t,GetSocket)(); + ////////////////////////////////////////////////////////////////////////// + //ITcpSocket + std_method(Bind)(const char* addr, unsigned int uport); + std_method_(os_sock_t, BindAccept)(const char* addr, unsigned int uport, int n); + std_method(SetReuseAddr)(bool bstart); + std_method(SetNoDelay)(bool bstart); + std_method(SetLinger)(bool bstart); + std_method(SetKeepalive)(bool bstart); + std_method(SetCork)(bool bstart); + std_method(SetNoSigPipe)(bool bstart); + ////////////////////////////////////////////////////////////////////////// + //IAsynTcpSocket + std_method(SetNonblock)(bool bstart); + std_method(SendBufLen)(int size); + std_method(RecvBufLen)(int size); + std_method(SendTime)(int sec); + std_method(RecvTime)(int sec); + std_method(SendLoWat)(int size); + std_method(RecvLoWat)(int size); + ////////////////////////////////////////////////////////////////////////// + os_sock_t m_socketFd; + //io_tcp_impl m_ioc; + +private: + +}; + + + + + + + +#endif \ No newline at end of file diff --git a/asynio/asynio.vcxproj b/asynio/asynio.vcxproj index a3f1c98b..0b9af1ca 100644 --- a/asynio/asynio.vcxproj +++ b/asynio/asynio.vcxproj @@ -75,7 +75,7 @@ Windows ..\lib\$(IntDir)$(TargetName).lib MachineX86 - wsock32.lib;libuv.lib;%(AdditionalDependencies) + ws2_32.lib;libuv.lib;psapi.lib;advapi32.lib;iphlpapi.lib;userenv.lib;%(AdditionalDependencies) @@ -100,10 +100,11 @@ true ..\lib\$(IntDir)$(TargetName).lib MachineX86 - wsock32.lib;libuv.lib;%(AdditionalDependencies) + ws2_32.lib;libuv.lib;psapi.lib;advapi32.lib;iphlpapi.lib;userenv.lib;%(AdditionalDependencies) + @@ -126,6 +127,7 @@ + diff --git a/asynio/asynioimpl.cpp b/asynio/asynioimpl.cpp index ef57cf4a..0eb775fa 100644 --- a/asynio/asynioimpl.cpp +++ b/asynio/asynioimpl.cpp @@ -2,6 +2,7 @@ #include "filereadimpl.h" #include "filewriteimpl.h" #include "tcpsocketimpl.h" +#include "asynctcpsocketimpl.h" CAsynIoImpl::CAsynIoImpl(void) { @@ -62,9 +63,15 @@ std_method_impl CAsynIoImpl::CreateWriteFile(IWriteFile** pWriteFile) *pWriteFile = reinterpret_cast(pObject); return hr; } -std_method_impl CAsynIoImpl::CreateAsynTcpSocket(IAsynTcpSocket** pAsynTcpSocket) +std_method_impl CAsynIoImpl::CreateAsyncTcpSocket(IAsyncTcpSocket** pAsynTcpSocket) { HRESULT hr = S_OK; + + IAsyncTcpSocket* pObject = NULL; + pObject = new CAsyncTcpSocketImpl; + pObject->AddRef(); + *pAsynTcpSocket = reinterpret_cast(pObject); + return hr; } std_method_impl CAsynIoImpl::CreateTcpSocket(ITcpSocket** pTcpSocket) @@ -74,12 +81,11 @@ std_method_impl CAsynIoImpl::CreateTcpSocket(ITcpSocket** pTcpSocket) ITcpSocket* pObject = NULL; pObject = new CTcpSocketImpl; pObject->AddRef(); - *pTcpSocket = reinterpret_cast(pObject); return hr; } -std_method_impl CAsynIoImpl::CreateAsynUdpSocket(IAsynUdpSocket** pAsynUdpSocket) +std_method_impl CAsynIoImpl::CreateAsyncUdpSocket(IAsyncUdpSocket** pAsynUdpSocket) { HRESULT hr = S_OK; return hr; diff --git a/asynio/asynioimpl.h b/asynio/asynioimpl.h index 55dabcf6..36314a73 100644 --- a/asynio/asynioimpl.h +++ b/asynio/asynioimpl.h @@ -36,9 +36,9 @@ public: std_method(CreateReadFile)(IReadFile** pReadFile); std_method(CreateWriteFile)(IWriteFile** pWriteFile); - std_method(CreateAsynTcpSocket)(IAsynTcpSocket** pAsynTcpSocket); + std_method(CreateAsyncTcpSocket)(IAsyncTcpSocket** pAsynTcpSocket); std_method(CreateTcpSocket)(ITcpSocket** pTcpSocket); - std_method(CreateAsynUdpSocket)(IAsynUdpSocket** pAsynUdpSocket); + std_method(CreateAsyncUdpSocket)(IAsyncUdpSocket** pAsynUdpSocket); std_method(CreateUdpSocket)(IUdpSocket** pUdpSocket); std_method(DeleteIo)(IModuleBase* pAsynIo); diff --git a/asynio/ioeventdef.h b/asynio/ioeventdef.h index 1f8a1bc2..b59eca6d 100644 --- a/asynio/ioeventdef.h +++ b/asynio/ioeventdef.h @@ -2,6 +2,11 @@ #define _IOEVENTDEF_H_ +#include "stdafx.h" + +#undef _WINSOCKAPI_ +#define _WINSOCKAPI_ + #include template diff --git a/asynio/ioeventloop.h b/asynio/ioeventloop.h index ce805bb0..3575523e 100644 --- a/asynio/ioeventloop.h +++ b/asynio/ioeventloop.h @@ -2,27 +2,18 @@ #define _IOEVENTLOOP_H_ #include "ioeventdef.h" +#include -typedef void* (*EventMsgProc)(unsigned long msgid,WPARAM wParam,LPARAM lParam); - -class ioeventbase +class ioeventloop : CSingletion { public: - ioeventbase() { - m_MsgProc = NULL; + ioeventloop() { + } - virtual ~ioeventbase() { + virtual ~ioeventloop() { } public: - void SetMsgProc(EventMsgProc Proc) - { - if (m_MsgProc != NULL) - m_MsgProc = Proc; - else { - - } - } uv_loop_t* GetEv() { return uvloopbase; } @@ -42,10 +33,11 @@ public: protected: evptr uvloopbase; - EventMsgProc m_MsgProc; }; + + class io_buff_t { public: io_buff_t() { diff --git a/asynio/iostreambase.h b/asynio/iostreambase.h index 16bde82b..b3f2798c 100644 --- a/asynio/iostreambase.h +++ b/asynio/iostreambase.h @@ -1,10 +1,9 @@ #ifndef _IOSTREAMBASE_H_ #define _IOSTREAMBASE_H_ +#include "ioeventdef.h" -#include "ioeventloop.h" - -class io_stream_t : public ioeventbase { +class io_stream_t { public: io_stream_t() { diff --git a/asynio/iotcpbase.cpp b/asynio/iotcpbase.cpp index a26aecff..d8b63559 100644 --- a/asynio/iotcpbase.cpp +++ b/asynio/iotcpbase.cpp @@ -1,2 +1,24 @@ #include "iotcpbase.h" +io_tcp_i::io_tcp_i() { + + tcphandler = NULL; +} + +io_tcp_i::~io_tcp_i() { + +} +int io_tcp_i::SockToIoEvent(os_sock_t sock) { + tcphandler = (uv_tcp_t*)malloc(sizeof(uv_tcp_t)); + uv_tcp_init(GetEv(), tcphandler); + return uv_tcp_open(tcphandler, sock); +} +int io_tcp_i::Connect() { + + return 1; +} +int io_tcp_i::Bind() { + + return 1; +} + diff --git a/asynio/iotcpbase.h b/asynio/iotcpbase.h index dd442d0a..63cc7d43 100644 --- a/asynio/iotcpbase.h +++ b/asynio/iotcpbase.h @@ -3,22 +3,19 @@ #include "iostreambase.h" - -class iotcpbase : public io_stream_t { +class io_tcp_i : public io_stream_t { public: - iotcpbase() { - tcphandler = NULL; - } - virtual ~iotcpbase() { - - } - int BindToIoEvent(SOCKET sock) { - tcphandler = (uv_tcp_t*)malloc(sizeof(uv_tcp_t)); - uv_tcp_init(GetEv(), tcphandler); - return uv_tcp_open(tcphandler, sock); - } + io_tcp_i(); + virtual ~io_tcp_i(); + int SockToIoEvent(os_sock_t sock); + int Connect(); + int Bind(); +public: + virtual int MsgProc(unsigned long msgid, WPARAM wParam, LPARAM lParam) = 0; private: - uv_tcp_t *tcphandler; + uv_tcp_t * tcphandler; }; + + #endif diff --git a/asynio/tcpsocketimpl.cpp b/asynio/tcpsocketimpl.cpp index 07438999..3d02c196 100644 --- a/asynio/tcpsocketimpl.cpp +++ b/asynio/tcpsocketimpl.cpp @@ -23,35 +23,17 @@ std_method_impl CTcpSocketImpl::CreateSocket() return hr; } -std_method_impl CTcpSocketImpl::Bind(const char* addr, unsigned int uport) -{ - HRESULT hr = S_OK; - - retrtpv(addr,E_FAIL) - retrtpv(uport,E_FAIL) - struct sockaddr_in sin; - sin.sin_family = AF_INET; - if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(addr))) { - return E_FAIL; - } - sin.sin_port = htons(uport); - if (connect(m_socketFd, (struct sockaddr*)(&sin),sizeof(struct sockaddr_in)) != 0) { - return E_FAIL; - } - - return hr; -} -std_method_type_impl(SOCKET) CTcpSocketImpl::BindAccept(const char* addr, unsigned int uport,int n) -{ - return -1; -} std_method_impl CTcpSocketImpl::CloseSocket() { HRESULT hr = S_OK; return hr; } +std_method_type_impl(os_sock_t) CTcpSocketImpl::GetSocket() +{ + return m_socketFd; +} std_method_type_impl(ssize_t) CTcpSocketImpl::Send(const char* buf,size_t len,int flags) { return -1; @@ -60,9 +42,30 @@ std_method_type_impl(ssize_t) CTcpSocketImpl::Recv(char* addr,size_t len,int fla { return -1; } -std_method_type_impl(SOCKET) CTcpSocketImpl::GetSocket() + + +std_method_impl CTcpSocketImpl::Bind(const char* addr, unsigned int uport) { - return m_socketFd; + HRESULT hr = S_OK; + + retrtpv(addr, E_FAIL) + retrtpv(uport, E_FAIL) + + struct sockaddr_in sin; + sin.sin_family = AF_INET; + if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(addr))) { + return E_FAIL; + } + sin.sin_port = htons(uport); + if (connect(m_socketFd, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) { + return E_FAIL; + } + + return hr; +} +std_method_type_impl(os_sock_t) CTcpSocketImpl::BindAccept(const char* addr, unsigned int uport, int n) +{ + return -1; } std_method_impl CTcpSocketImpl::SetReuseAddr(bool bstart) { diff --git a/asynio/tcpsocketimpl.h b/asynio/tcpsocketimpl.h index 2151ae68..721579c1 100644 --- a/asynio/tcpsocketimpl.h +++ b/asynio/tcpsocketimpl.h @@ -1,8 +1,6 @@ #ifndef _TCPSOCKIMPL_H_ #define _TCPSOCKIMPL_H_ - - #include "stdafx.h" #include @@ -15,22 +13,25 @@ public: virtual ~CTcpSocketImpl(void); UNKNOWN_IMP1(ITcpSocket); ////////////////////////////////////////////////////////////////////////// + //ISocket std_method(CreateSocket)(); - std_method(Bind)(const char* addr, unsigned int uport); - std_method_(SOCKET,BindAccept)(const char* addr, unsigned int uport,int n); std_method(CloseSocket)(); std_method_(ssize_t,Send)(const char* buf,size_t len,int flags); std_method_(ssize_t,Recv)(char* addr,size_t len,int flags); - std_method_(SOCKET,GetSocket)(); + std_method_(os_sock_t,GetSocket)(); + ////////////////////////////////////////////////////////////////////////// + //ITcpSocket + std_method(Bind)(const char* addr, unsigned int uport); + std_method_(os_sock_t, BindAccept)(const char* addr, unsigned int uport, int n); std_method(SetReuseAddr)(bool bstart); std_method(SetNoDelay)(bool bstart); std_method(SetLinger)(bool bstart); std_method(SetKeepalive)(bool bstart); std_method(SetCork)(bool bstart); std_method(SetNoSigPipe)(bool bstart); - ////////////////////////////////////////////////////////////////////////// - SOCKET m_socketFd; + os_sock_t m_socketFd; + private: diff --git a/extensions/include/io/iasynio.h b/extensions/include/io/iasynio.h index bc160091..1c481460 100644 --- a/extensions/include/io/iasynio.h +++ b/extensions/include/io/iasynio.h @@ -39,7 +39,7 @@ interface ISocket : public IModuleBase { std_method(CreateSocket)() = 0; std_method(CloseSocket)() = 0; - std_method_(SOCKET, GetSocket)() = 0; + std_method_(os_sock_t, GetSocket)() = 0; std_method_(ssize_t, Send)(const char* buf, size_t len, int flags) = 0; std_method_(ssize_t, Recv)(char* addr, size_t len, int flags) = 0; }; @@ -54,7 +54,7 @@ interface ISocket : public IModuleBase interface ITcpSocket : public ISocket { std_method(Bind)(const char* addr, unsigned int uport) = 0; - std_method_(SOCKET, BindAccept)(const char* addr, unsigned int uport, int n) = 0; + std_method_(os_sock_t, BindAccept)(const char* addr, unsigned int uport, int n) = 0; std_method(SetReuseAddr)(bool bstart) = 0; std_method(SetNoDelay)(bool bstart) = 0; std_method(SetLinger)(bool bstart) = 0; @@ -65,7 +65,7 @@ interface ITcpSocket : public ISocket }; MD_DEFINE_IID(ITcpSocket, "{6F7C433A-D7C5-4EFB-A525-701A675D7388}"); -interface IAsynTcpSocket : public ITcpSocket +interface IAsyncTcpSocket : public ITcpSocket { std_method(SetNonblock)(bool bstart) = 0; std_method(SendBufLen)(int size) = 0; @@ -74,9 +74,10 @@ interface IAsynTcpSocket : public ITcpSocket std_method(RecvTime)(int sec) = 0; std_method(SendLoWat)(int size) = 0; std_method(RecvLoWat)(int size) = 0; + }; -MD_DEFINE_IID(IAsynTcpSocket, "{6F7C433A-D7C5-4EFB-A525-701A675D7389}"); +MD_DEFINE_IID(IAsyncTcpSocket, "{6F7C433A-D7C5-4EFB-A525-701A675D7389}"); interface IUdpSocket : public ISocket @@ -85,11 +86,11 @@ interface IUdpSocket : public ISocket }; MD_DEFINE_IID(IUdpSocket, "{011A712D-1CD0-4F01-B365-35CB79AABBC6}"); -interface IAsynUdpSocket : public ISocket +interface IAsyncUdpSocket : public ISocket { }; -MD_DEFINE_IID(IAsynUdpSocket, "{AD708F28-58CB-46CE-A672-A16662944D8A}"); +MD_DEFINE_IID(IAsyncUdpSocket, "{AD708F28-58CB-46CE-A672-A16662944D8A}"); @@ -97,9 +98,9 @@ interface IAsynIo : public IModuleBase { std_method(CreateReadFile)(IReadFile** pReadFile) = 0; std_method(CreateWriteFile)(IWriteFile** pWriteFile) = 0; - std_method(CreateAsynTcpSocket)(IAsynTcpSocket** pAsynTcpSocket) = 0; + std_method(CreateAsyncTcpSocket)(IAsyncTcpSocket** pAsynTcpSocket) = 0; std_method(CreateTcpSocket)(ITcpSocket** pTcpSocket) = 0; - std_method(CreateAsynUdpSocket)(IAsynUdpSocket** pAsynUdpSocket) = 0; + std_method(CreateAsyncUdpSocket)(IAsyncUdpSocket** pAsynUdpSocket) = 0; std_method(CreateUdpSocket)(IUdpSocket** pUdpSocket) = 0; std_method(DeleteIo)(IModuleBase* pAsynIo) = 0; }; diff --git a/include/dlcom/byunknown.hpp b/include/dlcom/byunknown.hpp index 7ae27ac1..661192f2 100644 --- a/include/dlcom/byunknown.hpp +++ b/include/dlcom/byunknown.hpp @@ -53,13 +53,13 @@ typedef long HRESULT; -#define std_method(method) virtual HRESULT BY_STDCALL method -#define std_method_impl HRESULT BY_STDCALL +#define std_method(method) virtual HRESULT OS_STDCALL method +#define std_method_impl HRESULT OS_STDCALL -#define std_method_(type,method) virtual type BY_STDCALL method -#define std_method_type_impl(type) type BY_STDCALL +#define std_method_(type,method) virtual type OS_STDCALL method +#define std_method_type_impl(type) type OS_STDCALL diff --git a/include/dlcom/loadcom.hpp b/include/dlcom/loadcom.hpp index 30c48ba7..374f8458 100644 --- a/include/dlcom/loadcom.hpp +++ b/include/dlcom/loadcom.hpp @@ -14,10 +14,10 @@ MD_EXPORTS DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID* ppv); -typedef HRESULT (BY_STDCALL *DefineDllGetClassObject)(REFCLSID rclsid,REFIID riid,LPVOID* ppv); -typedef HRESULT (BY_STDCALL *DefineDllCanUnloadNow)(void); -typedef HRESULT (BY_STDCALL *DefineDllRegisterServer)(void); -typedef HRESULT (BY_STDCALL *DefineDllUnregisterServer)(void); +typedef HRESULT (OS_STDCALL *DefineDllGetClassObject)(REFCLSID rclsid,REFIID riid,LPVOID* ppv); +typedef HRESULT (OS_STDCALL *DefineDllCanUnloadNow)(void); +typedef HRESULT (OS_STDCALL *DefineDllRegisterServer)(void); +typedef HRESULT (OS_STDCALL *DefineDllUnregisterServer)(void); diff --git a/include/util/bits.hpp b/include/util/bits.hpp new file mode 100644 index 00000000..c2b7b75d --- /dev/null +++ b/include/util/bits.hpp @@ -0,0 +1,35 @@ +#ifndef _UTILBITS_H_ +#define _UTILBITS_H_ + +#if TARGET_BITS == 64 + + #if (TARGET_OS == OS_POSIX ) + typedef long long INT_PTR, *PINT_PTR; + typedef unsigned long long UINT_PTR, *PUINT_PTR; + typedef long long LONG_PTR, *PLONG_PTR; + typedef unsigned long long ULONG_PTR, *PULONG_PTR; + #elif (TAGET_OS == OS_MAC) + typedef long long INT_PTR, *PINT_PTR; + typedef unsigned long long UINT_PTR, *PUINT_PTR; + typedef long long LONG_PTR, *PLONG_PTR; + typedef unsigned long long ULONG_PTR, *PULONG_PTR; + #endif + +#else + #if (TARGET_OS == OS_POSIX ) + typedef int INT_PTR, *PINT_PTR; + typedef unsigned int UINT_PTR, *PUINT_PTR; + typedef long LONG_PTR, *PLONG_PTR; + typedef unsigned long ULONG_PTR, *PULONG_PTR; + + + #elif (TAGET_OS == OS_MAC) + typedef int INT_PTR, *PINT_PTR; + typedef unsigned int UINT_PTR, *PUINT_PTR; + typedef long LONG_PTR, *PLONG_PTR; + typedef unsigned long ULONG_PTR, *PULONG_PTR; + #endif +#endif + + +#endif \ No newline at end of file diff --git a/include/util/calldll.hpp b/include/util/calldll.hpp index aae4abe1..3569610c 100644 --- a/include/util/calldll.hpp +++ b/include/util/calldll.hpp @@ -10,7 +10,7 @@ namespace util { #define offsetof(s,m) ((size_t)&reinterpret_cast((((s*)0)->m))) #endif // !offsetof - class BY_NO_VTABLE IImpModuleBase + class CPP_NO_VTABLE IImpModuleBase { public: struct STFunDesc @@ -119,7 +119,7 @@ namespace util { }; template - class BY_NO_VTABLE tImpModuleMid : public IImpModuleBase + class CPP_NO_VTABLE tImpModuleMid : public IImpModuleBase { public: typedef tDerived DerivedType; diff --git a/include/util/common.hpp b/include/util/common.hpp new file mode 100644 index 00000000..cc8afdf8 --- /dev/null +++ b/include/util/common.hpp @@ -0,0 +1,124 @@ +#ifndef _UTILCOMMON_H_ +#define _UTILCOMMON_H_ + + + +#ifndef _OFF_T_DEFINED + #define _OFF_T_DEFINED + typedef long _off_t; +#endif + + +#ifdef CPP_NO_VTABLE +#undef CPP_NO_VTABLE +#endif + +#if defined(_MSC_VER) +#define CPP_NO_VTABLE __declspec(novtable) +#else +#define CPP_NO_VTABLE +#endif + + +#if (CPP_COMPILER == CC_MSVC ) + #define __attribute__(x) +#elif (CPP_COMPILER == CC_GCC ) + +#endif + + +#if(CPP_COMPILER == CC_MSVC) + #define _aligned(g) __declspec(align(g)) +#else + #define _aligned(g) __attribute__((aligned(g))) +#endif + +#define __aligned(g, type) _aligned(g) type + + +#define PACK_ONEBYTE __attribute__((packed)) +#define PACK_EIGHTBYTE __attribute__((aligned(8))) + + +#ifndef MAX_PATH +#define MAX_PATH 260 +#endif + +//dll +//__declspec(dllexport) +//so no display +#ifdef __GNUC__ +#define OS_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden"))) +#else +#define OS_VISIBILITY_HIDDEN +#endif + +//so display +#ifdef __GNUC__ +#define OS_VISIBILITY_DEFAULT __attribute__ ((visibility ("default"))) +#else +#define OS_VISIBILITY_DEFAULT +#endif + + +#ifdef __GNUC__ +#define _unused __attribute__ ((__unused__)) +#else +#define _unused +#endif + + +#define OS_HIDDEN_(type) OS_VISIBILITY_HIDDEN type +#define OS_EXTERNAL_VIS_(type) OS_VISIBILITY_DEFAULT type + +#define OS_HIDDEN OS_VISIBILITY_HIDDEN +#define OS_EXTERNAL_VIS OS_VISIBILITY_DEFAULT + +#undef IMETHOD_VISIBILITY +#define IMETHOD_VISIBILITY OS_VISIBILITY_HIDDEN + +#ifdef _MSC_VER + +#define OS_STDCALL __stdcall +#define OS_IMPORT __declspec(dllimport) +#define OS_IMPORT_(type) type __declspec(dllimport) __stdcall +#define OS_EXPORT __declspec(dllexport) +#define OS_EXPORT_(type) type __declspec(dllexport) __stdcall +#define OS_IMETHOD_(type) virtual type __stdcall +#define OS_IMETHODIMP_(type) type __stdcall +#define OS_METHOD_(type) type __stdcall +#define OS_CALLBACK_(_type, _name) _type (__stdcall * _name) +#define OS_EXPORT_STATIC_MEMBER_(type) type +#define OS_IMPORT_STATIC_MEMBER_(type) type + +#else + +#define OS_STDCALL +#define OS_IMPORT NS_EXTERNAL_VIS +#define OS_IMPORT_(type) NS_EXTERNAL_VIS_(type) +#define OS_EXPORT NS_EXTERNAL_VIS +#define OS_EXPORT_(type) NS_EXTERNAL_VIS_(type) +#define OS_IMETHOD_(type) virtual IMETHOD_VISIBILITY type NS_DEFCALL +#define OS_IMETHODIMP_(type) type +#define OS_METHOD_(type) type +#define OS_CALLBACK_(_type, _name) _type (* _name) +#define OS_EXPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type) +#define OS_IMPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type) + +#endif + + + + +#ifdef __GNUC__ +#define BY_STDCALL_FUNCPROTO(ret, name, class, func, args) \ + typeof(&class::func) name +#else +#define BY_STDCALL_FUNCPROTO(ret, name, class, func, args) \ + ret (NS_STDCALL class::*name) args +#endif + + + + +#endif \ No newline at end of file diff --git a/include/util/core.hpp b/include/util/core.hpp index d8aac20d..8c68d225 100644 --- a/include/util/core.hpp +++ b/include/util/core.hpp @@ -2,56 +2,7 @@ #define _UTIL_CORE_H_ - -#define OS_WINDOWS 0 -#define OS_NATIVE 10 -#define OS_POSIX 20 -#define OS_MAC 30 - -#define CC_MSVC 0 -#define CC_GCC 1 - - -#define ARCH_32BIT 32 -#define ARCH_64BIT 64 - -#define TARGET_X86 0 -#define TARGET_NOT_X86 1 -#define TARGET_X64 2 - -#ifdef _MSC_VER - #define TARGET_OS OS_WINDOWS - #define CPP_COMPILER CC_MSVC - -#endif - -#ifdef __GNUC__ - #define TARGET_OS OS_POSIX - #define CPP_COMPILER CC_GCC -#endif - -#ifdef _MAC - #define TARGET_OS OS_MAC - #define CPP_COMPILER CC_MSVC - -#endif - - -#if (defined(i386) || defined(_i386) || defined(__i386) || defined(__i386__)) || (defined(_WIN32)) || defined(_M_IX86) - #define TARGET_BITS ARCH_32BIT -#endif - -#if defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) - #undef TARGET_BITS - #define TARGET_BITS ARCH_64BIT -#endif - -#if !defined(TARGET_BITS) - #define TARGET_BITS ARCH_32BIT -#endif - - - +#include #include #include @@ -59,529 +10,43 @@ #include #include #include - #include - #include #include - #include #include - - #if (TARGET_OS == OS_WINDOWS) - #include - #pragma warning(disable:4996) - #define byint64 __int64 - #define byuint64 unsigned __int64 - #define FMT_I64D "%I64d" - #define FMT_I64U "%I64u" - typedef SSIZE_T ssize_t; - + #include #elif (TARGET_OS == OS_POSIX) - #include - #include - #include - #include - - //address - #include - //setsockopt opations - #include - #include - - #define byint64 long long int - #define byuint64 unsigned long long int - #define FMT_I64D "%lld" - #define FMT_I64U "%llu" - + #include #elif (TAGET_OS == OS_MAC) - #include - #include -#endif - - - - - -#if TARGET_BITS == 64 - - #if (TARGET_OS == OS_POSIX ) - typedef long long INT_PTR, *PINT_PTR; - typedef unsigned long long UINT_PTR, *PUINT_PTR; - typedef long long LONG_PTR, *PLONG_PTR; - typedef unsigned long long ULONG_PTR, *PULONG_PTR; - #elif (TAGET_OS == OS_MAC) - typedef long long INT_PTR, *PINT_PTR; - typedef unsigned long long UINT_PTR, *PUINT_PTR; - typedef long long LONG_PTR, *PLONG_PTR; - typedef unsigned long long ULONG_PTR, *PULONG_PTR; - #endif -#else - - #if (TARGET_OS == OS_POSIX ) - typedef int INT_PTR, *PINT_PTR; - typedef unsigned int UINT_PTR, *PUINT_PTR; - typedef long LONG_PTR, *PLONG_PTR; - typedef unsigned long ULONG_PTR, *PULONG_PTR; - - - #elif (TAGET_OS == OS_MAC) - typedef int INT_PTR, *PINT_PTR; - typedef unsigned int UINT_PTR, *PUINT_PTR; - typedef long LONG_PTR, *PLONG_PTR; - typedef unsigned long ULONG_PTR, *PULONG_PTR; - #endif -#endif - - -#ifndef _OFF_T_DEFINED - #define _OFF_T_DEFINED - typedef long _off_t; -#endif - - -#if (CPP_COMPILER == CC_GCC ) - - -#ifndef FALSE -#define FALSE 0 -#define TRUE 1 -#endif // !FALSE - - -#ifndef NULL - #ifdef __cplusplus - #define NULL 0 - #else - #define NULL ((void *)0) - #endif -#endif - -typedef long long LONGLONG; -typedef unsigned long long ULONGLONG; - - -typedef unsigned int UINT; -typedef int INT; -typedef long BOOL; -typedef unsigned long ULONG; -typedef ULONG *PULONG; -typedef unsigned short USHORT; -typedef USHORT *PUSHORT; -typedef unsigned char UCHAR; -typedef UCHAR *PUCHAR; -typedef short SHORT; -typedef unsigned char byte; -typedef double DOUBLE; -typedef float FLOAT; -typedef void *PVOID; -typedef short VARIANT_BOOL; - - - -#ifndef _WCHAR_DEFINED -#define _WCHAR_DEFINED -typedef wchar_t WCHAR; -typedef WCHAR OLECHAR; -typedef OLECHAR *BSTR; -typedef WCHAR *LPWSTR; -typedef const WCHAR *LPCWSTR; -#endif // !_WCHAR_DEFINED - -typedef char CHAR; -typedef CHAR *LPSTR; -typedef const CHAR *LPCSTR; - - - -#ifdef _UNICODE - #define LPCTSTR LPCWSTR - #define _stprintf _swprintf - #define _T(x) L##x - typedef wchar_t TCHAR; - -#else - #define LPCTSTR LPCSTR - #define _stprintf sprintf - #define _T(x) x - typedef char TCHAR; + #include #endif - -typedef UINT_PTR WPARAM; -typedef LONG_PTR LPARAM; -typedef LONG_PTR LRESULT; - -#ifndef VOID -#define VOID void -typedef void* LPVOID; -#endif // !VOID - - - - - -#ifndef _BYTE_DEFINED -#define _BYTE_DEFINED -typedef byte BYTE; -#endif // !_BYTE_DEFINED - -#ifndef _WORD_DEFINED -#define _WORD_DEFINED -typedef unsigned short WORD; -#endif // !_WORD_DEFINED - - -#ifndef _LONG_DEFINED -#define _LONG_DEFINED -typedef long LONG; -#endif // !_LONG_DEFINED - -#ifndef _WPARAM_DEFINED -#define _WPARAM_DEFINED -typedef UINT_PTR WPARAM; -#endif // _WPARAM_DEFINED - -#ifndef _DWORD_DEFINED -#define _DWORD_DEFINED -typedef unsigned long DWORD; -#endif // !_DWORD_DEFINED -#ifndef _LPARAM_DEFINED -#define _LPARAM_DEFINED -typedef LONG_PTR LPARAM; - -#endif // !_LPARAM_DEFINED -#ifndef _LRESULT_DEFINED -#define _LRESULT_DEFINED -typedef LONG_PTR LRESULT; - -#endif // !_LRESULT_DEFINED - - - -typedef struct _FILETIME { - DWORD dwLowDateTime; - DWORD dwHighDateTime; -} FILETIME, *PFILETIME, *LPFILETIME; -typedef const FILETIME *PCFILETIME, *LPCFILETIME; - - - -typedef void* HANDLE; -typedef void* HMODULE; -typedef void* HINSTANCE; -typedef void* HTASK; -typedef void* HKEY; -typedef void* HDESK; -typedef void* HMF; -typedef void* HEMF; -typedef void* HPEN; -typedef void* HRSRC; -typedef void* HSTR; -typedef void* HWINSTA; -typedef void* HKL; -typedef void* HGDIOBJ; -typedef HANDLE HDWP; - -#ifndef _HFILE_DEFINED -#define _HFILE_DEFINED -typedef INT HFILE; - -#endif // !_HFILE_DEFINED -#ifndef _LPWORD_DEFINED -#define _LPWORD_DEFINED -typedef WORD *LPWORD; -#endif // !_LPWORD_DEFINED -#ifndef _LPDWORD_DEFINED -#define _LPDWORD_DEFINED -typedef DWORD *LPDWORD; -#endif // !_LPDWORD_DEFINED - - -#ifndef _COLORREF_DEFINED -#define _COLORREF_DEFINED -typedef DWORD COLORREF; -#endif // !_COLORREF_DEFINED - -#ifndef _LPCOLORREF_DEFINED -#define _LPCOLORREF_DEFINED -typedef DWORD *LPCOLORREF; -#endif // !_LPCOLORREF_DEFINED - -typedef HANDLE *LPHANDLE; -typedef struct _RECTL -{ - LONG left; - LONG top; - LONG right; - LONG bottom; - -}RECTL; - -typedef struct _RECTL *PRECTL; - -typedef struct _RECTL *LPRECTL; - -typedef struct tagPOINT -{ - LONG x; - LONG y; -} POINT; - -typedef struct tagPOINT *PPOINT; - -typedef struct tagPOINT *LPPOINT; - -typedef struct _POINTL -{ - LONG x; - LONG y; -}POINTL; -typedef struct _POINTL *PPOINTL; -typedef struct tagSIZE -{ - LONG cx; - LONG cy; -} SIZE; - -typedef struct tagSIZE *PSIZE; -typedef struct tagSIZE *LPSIZE; - -typedef struct tagSIZEL -{ - LONG cx; - LONG cy; -}SIZEL; - -typedef struct tagSIZEL *PSIZEL; -typedef struct tagSIZEL *LPSIZEL; - - -typedef struct _LARGE_INTEGER -{ - LONGLONG QuadPart; -}LARGE_INTEGER; - -typedef LARGE_INTEGER *PLARGE_INTEGER; - -typedef struct _ULARGE_INTEGER -{ - ULONGLONG QuadPart; -} ULARGE_INTEGER; - - -typedef LONG SCODE; - -#define DLL_PROCESS_ATTACH 1 -#define DLL_THREAD_ATTACH 2 -#define DLL_THREAD_DETACH 3 -#define DLL_PROCESS_DETACH 0 - -#define MAX_PATH 260 -#define _MAX_PATH 260 // max. length of full pathname -#define _MAX_DRIVE 3 // max. length of drive component -#define _MAX_DIR 256 // max. length of path component -#define _MAX_FNAME 256 // max. length of file name component -#define _MAX_EXT 256 // max. length of extension component - - +#include +#include - - - -#endif - - -#if(CPP_COMPILER == CC_MSVC) - #define _aligned(g) __declspec(align(g)) -#else - #define _aligned(g) __attribute__((aligned(g))) -#endif - -#define __aligned(g, type) _aligned(g) type - - -#define PACK_ONEBYTE __attribute__((packed)) -#define PACK_EIGHTBYTE __attribute__((aligned(8))) - - - - -#ifndef MAX_PATH -#define MAX_PATH 260 -#endif - - -#if (CPP_COMPILER == CC_MSVC ) - #define __attribute__(x) -#elif (CPP_COMPILER == CC_GCC ) - -#endif - - -#ifdef _MAC -#define CALLBACK PASCAL -#define WINAPI CDECL -#define WINAPIV CDECL -#define APIENTRY WINAPI -#define APIPRIVATE CDECL -#ifdef _68K_ -#define PASCAL __pascal -#else -#define PASCAL -#endif -#elif _MSC_VER - -#ifndef WINAPI -#define WINAPI __stdcall -#endif - -#ifndef CALLBACK -#define CALLBACK __stdcall -#endif - -#ifndef WINAPIV -#define WINAPIV __cdecl -#endif - - -#ifndef APIENTRY -#define APIENTRY WINAPI -#endif - - - -#ifndef APIPRIVATE -#define APIPRIVATE __stdcall -#endif - - -#ifndef PASCAL -#define PASCAL __stdcall -#endif - - -#elif __GNUC__ -#define CALLBACK -#define WINAPI -#define WINAPIV -#define APIENTRY WINAPI -#define APIPRIVATE -#define PASCAL pascal -#endif - - -#ifdef BY_NO_VTABLE -#undef BY_NO_VTABLE -#endif - -#if defined(_MSC_VER) -#define BY_NO_VTABLE __declspec(novtable) -#else -#define BY_NO_VTABLE -#endif - - -//dll -//__declspec(dllexport) -//so no display -#ifdef __GNUC__ -#define BY_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden"))) -#else -#define BY_VISIBILITY_HIDDEN -#endif - -//so display -#ifdef __GNUC__ -#define BY_VISIBILITY_DEFAULT __attribute__ ((visibility ("default"))) -#else -#define BY_VISIBILITY_DEFAULT -#endif - - -#ifdef __GNUC__ -#define _unused __attribute__ ((__unused__)) -#else -#define _unused -#endif - - - - -#define BY_HIDDEN_(type) BY_VISIBILITY_HIDDEN type -#define BY_EXTERNAL_VIS_(type) BY_VISIBILITY_DEFAULT type - -#define BY_HIDDEN BY_VISIBILITY_HIDDEN -#define BY_EXTERNAL_VIS BY_VISIBILITY_DEFAULT - -#undef IMETHOD_VISIBILITY -#define IMETHOD_VISIBILITY BY_VISIBILITY_HIDDEN - -#ifdef _MSC_VER - -#define BY_STDCALL __stdcall -#define BY_IMPORT __declspec(dllimport) -#define BY_IMPORT_(type) type __declspec(dllimport) __stdcall -#define BY_EXPORT __declspec(dllexport) -#define BY_EXPORT_(type) type __declspec(dllexport) __stdcall -#define BY_IMETHOD_(type) virtual type __stdcall -#define BY_IMETHODIMP_(type) type __stdcall -#define BY_METHOD_(type) type __stdcall -#define BY_CALLBACK_(_type, _name) _type (__stdcall * _name) -#define BY_EXPORT_STATIC_MEMBER_(type) type -#define BY_IMPORT_STATIC_MEMBER_(type) type - -#else - -#define BY_STDCALL -#define BY_IMPORT NS_EXTERNAL_VIS -#define BY_IMPORT_(type) NS_EXTERNAL_VIS_(type) -#define BY_EXPORT NS_EXTERNAL_VIS -#define BY_EXPORT_(type) NS_EXTERNAL_VIS_(type) -#define BY_IMETHOD_(type) virtual IMETHOD_VISIBILITY type NS_DEFCALL -#define BY_IMETHODIMP_(type) type -#define BY_METHOD_(type) type -#define BY_CALLBACK_(_type, _name) _type (* _name) -#define BY_EXPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type) -#define BY_IMPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type) - -#endif - - - - -#ifdef __GNUC__ -#define BY_STDCALL_FUNCPROTO(ret, name, class, func, args) \ - typeof(&class::func) name -#else -#define BY_STDCALL_FUNCPROTO(ret, name, class, func, args) \ - ret (NS_STDCALL class::*name) args +#if (TARGET_OS == OS_WINDOWS) + #include +#elif (TARGET_OS == OS_POSIX) + #include +#elif (TAGET_OS == OS_MAC) + #include #endif +#ifdef __cplusplus + #define Memory_Allocate new (std::nothrow) -#ifndef EXTERN_C - #ifdef __cplusplus - #define EXTERN_C extern "C" - #define STDNOTHROW (std::nothrow) - #else - #define EXTERN_C extern - #define STDNOTHROW (std::nothrow) + #ifndef EXTERN_C + #define EXTERN_C extern "C" #endif -#endif - - - - - -#ifdef __cplusplus - #define Memory_Allocate new (std::nothrow) + #define STDNOTHROW (std::nothrow) #ifndef tstring #ifdef _UNICODE @@ -592,32 +57,22 @@ typedef LONG SCODE; #define _T(x) x #endif #endif - #else #define Memory_Allocate malloc -#endif - - - - - + #ifndef EXTERN_C + #define EXTERN_C extern "C" + #endif + #define STDNOTHROW +#endif #ifdef __GNUC__ -#define MODULE_API HRESULT BY_VISIBILITY_DEFAULT +#define MODULE_API HRESULT OS_VISIBILITY_DEFAULT #else -#define MODULE_API HRESULT BY_STDCALL +#define MODULE_API HRESULT OS_STDCALL #endif - - -#define MD_EXPORTS EXTERN_C MODULE_API - - - - - - +#define MD_EXPORTS EXTERN_C MODULE_API #define FAILEXIT_N(x, _h_r_) {if(!(x)) return _h_r_; } #define FAILEXIT_FALSE_N(x) {FAILEXIT_N((x),FALSE)} @@ -626,11 +81,9 @@ typedef LONG SCODE; #define FAILEXIT_OTHER_N(x) {FAILEXIT_N((x),0xFFFFFFFF)} #define FAILEXIT_FAIL_ONE(x) {FAILEXIT_N((x),1)} #define FAILEXIT_FAIL_ZERO(x) {FAILEXIT_N((x),0)} - #define SAF_DELET(ptr) if((ptr)){delete ptr;ptr=(0);} #define SAF_DELET_ARRAY(ptr) if((ptr)){delete [] ptr;ptr=(0);} - #define _max(a,b) ((a)>(b)?(a):(b)) #define _min(a,b) ((a)>(b)?(b):(a)) #define bzero(p,s) memset(p,0,s) diff --git a/include/util/locksection.hpp b/include/util/locksection.hpp index abfe9220..d273d4a4 100644 --- a/include/util/locksection.hpp +++ b/include/util/locksection.hpp @@ -165,6 +165,7 @@ public: }; +/* template class CSingleInstance : public _TInterface { @@ -212,7 +213,7 @@ public: } }; - +*/ template diff --git a/include/util/posix/osdef.h b/include/util/posix/osdef.h new file mode 100644 index 00000000..04eef1d1 --- /dev/null +++ b/include/util/posix/osdef.h @@ -0,0 +1,32 @@ +#ifndef _OSDEF_H_ +#define _OSDEF_H_ + +#include +#include +#include +#include + + +//address +#include +//setsockopt opations +#include +#include + + #include + +#define byint64 long long int +#define byuint64 unsigned long long int +#define FMT_I64D "%lld" +#define FMT_I64U "%llu" + + +#define CALLBACK +#define WINAPI +#define WINAPIV +#define APIENTRY WINAPI +#define APIPRIVATE +#define PASCAL pascal + + +#endif diff --git a/include/util/posix/ossysdef.h b/include/util/posix/ossysdef.h new file mode 100644 index 00000000..6a46e5c2 --- /dev/null +++ b/include/util/posix/ossysdef.h @@ -0,0 +1,250 @@ +#ifndef _OSSYSDEF_H_ +#define _OSSYSDEF_H_ + +#include + +#ifndef FALSE +#define FALSE 0 +#define TRUE 1 +#endif // !FALSE + + +#ifndef NULL + #ifdef __cplusplus + #define NULL 0 + #else + #define NULL ((void *)0) + #endif +#endif + +typedef long long LONGLONG; +typedef unsigned long long ULONGLONG; + + +typedef unsigned int UINT; +typedef int INT; +typedef long BOOL; +typedef unsigned long ULONG; +typedef ULONG *PULONG; +typedef unsigned short USHORT; +typedef USHORT *PUSHORT; +typedef unsigned char UCHAR; +typedef UCHAR *PUCHAR; +typedef short SHORT; +typedef unsigned char byte; +typedef double DOUBLE; +typedef float FLOAT; +typedef void *PVOID; +typedef short VARIANT_BOOL; + + + +#ifndef _WCHAR_DEFINED +#define _WCHAR_DEFINED +typedef wchar_t WCHAR; +typedef WCHAR OLECHAR; +typedef OLECHAR *BSTR; +typedef WCHAR *LPWSTR; +typedef const WCHAR *LPCWSTR; +#endif // !_WCHAR_DEFINED + +typedef char CHAR; +typedef CHAR *LPSTR; +typedef const CHAR *LPCSTR; + + + +#ifdef _UNICODE + #define LPCTSTR LPCWSTR + #define _stprintf _swprintf + #define _T(x) L##x + typedef wchar_t TCHAR; + +#else + #define LPCTSTR LPCSTR + #define _stprintf sprintf + #define _T(x) x + typedef char TCHAR; +#endif + + + +typedef UINT_PTR WPARAM; +typedef LONG_PTR LPARAM; +typedef LONG_PTR LRESULT; + +#ifndef VOID +#define VOID void +typedef void* LPVOID; +#endif // !VOID + + + + + +#ifndef _BYTE_DEFINED +#define _BYTE_DEFINED +typedef byte BYTE; +#endif // !_BYTE_DEFINED + +#ifndef _WORD_DEFINED +#define _WORD_DEFINED +typedef unsigned short WORD; +#endif // !_WORD_DEFINED + + +#ifndef _LONG_DEFINED +#define _LONG_DEFINED +typedef long LONG; +#endif // !_LONG_DEFINED + +#ifndef _WPARAM_DEFINED +#define _WPARAM_DEFINED +typedef UINT_PTR WPARAM; +#endif // _WPARAM_DEFINED + +#ifndef _DWORD_DEFINED +#define _DWORD_DEFINED +typedef unsigned long DWORD; +#endif // !_DWORD_DEFINED +#ifndef _LPARAM_DEFINED +#define _LPARAM_DEFINED +typedef LONG_PTR LPARAM; + +#endif // !_LPARAM_DEFINED +#ifndef _LRESULT_DEFINED +#define _LRESULT_DEFINED +typedef LONG_PTR LRESULT; + +#endif // !_LRESULT_DEFINED + + + +typedef struct _FILETIME { + DWORD dwLowDateTime; + DWORD dwHighDateTime; +} FILETIME, *PFILETIME, *LPFILETIME; +typedef const FILETIME *PCFILETIME, *LPCFILETIME; + + + +typedef void* HANDLE; +typedef void* HMODULE; +typedef void* HINSTANCE; +typedef void* HTASK; +typedef void* HKEY; +typedef void* HDESK; +typedef void* HMF; +typedef void* HEMF; +typedef void* HPEN; +typedef void* HRSRC; +typedef void* HSTR; +typedef void* HWINSTA; +typedef void* HKL; +typedef void* HGDIOBJ; +typedef HANDLE HDWP; + +#ifndef _HFILE_DEFINED +#define _HFILE_DEFINED +typedef INT HFILE; + +#endif // !_HFILE_DEFINED +#ifndef _LPWORD_DEFINED +#define _LPWORD_DEFINED +typedef WORD *LPWORD; +#endif // !_LPWORD_DEFINED +#ifndef _LPDWORD_DEFINED +#define _LPDWORD_DEFINED +typedef DWORD *LPDWORD; +#endif // !_LPDWORD_DEFINED + + +#ifndef _COLORREF_DEFINED +#define _COLORREF_DEFINED +typedef DWORD COLORREF; +#endif // !_COLORREF_DEFINED + +#ifndef _LPCOLORREF_DEFINED +#define _LPCOLORREF_DEFINED +typedef DWORD *LPCOLORREF; +#endif // !_LPCOLORREF_DEFINED + +typedef HANDLE *LPHANDLE; +typedef struct _RECTL +{ + LONG left; + LONG top; + LONG right; + LONG bottom; + +}RECTL; + +typedef struct _RECTL *PRECTL; + +typedef struct _RECTL *LPRECTL; + +typedef struct tagPOINT +{ + LONG x; + LONG y; +} POINT; + +typedef struct tagPOINT *PPOINT; + +typedef struct tagPOINT *LPPOINT; + +typedef struct _POINTL +{ + LONG x; + LONG y; +}POINTL; +typedef struct _POINTL *PPOINTL; +typedef struct tagSIZE +{ + LONG cx; + LONG cy; +} SIZE; + +typedef struct tagSIZE *PSIZE; +typedef struct tagSIZE *LPSIZE; + +typedef struct tagSIZEL +{ + LONG cx; + LONG cy; +}SIZEL; + +typedef struct tagSIZEL *PSIZEL; +typedef struct tagSIZEL *LPSIZEL; + + +typedef struct _LARGE_INTEGER +{ + LONGLONG QuadPart; +}LARGE_INTEGER; + +typedef LARGE_INTEGER *PLARGE_INTEGER; + +typedef struct _ULARGE_INTEGER +{ + ULONGLONG QuadPart; +} ULARGE_INTEGER; + + +typedef LONG SCODE; + +#define DLL_PROCESS_ATTACH 1 +#define DLL_THREAD_ATTACH 2 +#define DLL_THREAD_DETACH 3 +#define DLL_PROCESS_DETACH 0 + +#define MAX_PATH 260 +#define _MAX_PATH 260 // max. length of full pathname +#define _MAX_DRIVE 3 // max. length of drive component +#define _MAX_DIR 256 // max. length of path component +#define _MAX_FNAME 256 // max. length of file name component +#define _MAX_EXT 256 // max. length of extension component + + + +#endif \ No newline at end of file diff --git a/include/util/singletion.hpp b/include/util/singletion.hpp new file mode 100644 index 00000000..8aa4e6f2 --- /dev/null +++ b/include/util/singletion.hpp @@ -0,0 +1,52 @@ +#ifndef _SINGLETION_H_ +#define _SINGLETION_H_ + +#include +#include +#include + +namespace util { +template +class CSingletion : public _TInterface +{ +protected: + LONG m_dwRef; + + inline ULONG Increment(long* p) + { + return lockadd(p); + } + inline ULONG Decrement(long* p) + { + return lockdel(p); + } + +public: + CSingletion() + { + m_dwRef = 1L; + } + virtual ~CSingletion() + { + Decrement(&m_dwRef); + } + + virtual long AddRef() + { + return Increment(&m_dwRef); + } + virtual long ReleaseRef() + { + LONG l = Decrement(&m_dwRef); + if (l == 0) + { + delete this; + } + return l; + } + +}; + +} + +#endif diff --git a/include/util/socketdef.hpp b/include/util/socketdef.hpp index af86118e..d4db7707 100644 --- a/include/util/socketdef.hpp +++ b/include/util/socketdef.hpp @@ -4,7 +4,7 @@ #include #if (TARGET_OS == OS_WINDOWS) - typedef SSIZE_T ssize_t; + typedef SOCKET os_sock_t; #elif (TARGET_OS == OS_POSIX) diff --git a/include/util/targetos.hpp b/include/util/targetos.hpp new file mode 100644 index 00000000..45296a90 --- /dev/null +++ b/include/util/targetos.hpp @@ -0,0 +1,55 @@ +#ifndef _UTILTARGETBITS_H_ +#define _UTILTARGETBITS_H_ + + + + +#define OS_WINDOWS 0 +#define OS_NATIVE 10 +#define OS_POSIX 20 +#define OS_MAC 30 + +#define CC_MSVC 0 +#define CC_GCC 1 + + +#define ARCH_32BIT 32 +#define ARCH_64BIT 64 + +#define TARGET_X86 0 +#define TARGET_NOT_X86 1 +#define TARGET_X64 2 + +#ifdef _MSC_VER + #define TARGET_OS OS_WINDOWS + #define CPP_COMPILER CC_MSVC +#endif + +#ifdef __GNUC__ + #define TARGET_OS OS_POSIX + #define CPP_COMPILER CC_GCC +#endif + +#ifdef _MAC + #define TARGET_OS OS_MAC + #define CPP_COMPILER CC_XCODE +#endif + + + +#if (defined(i386) || defined(_i386) || defined(__i386) || defined(__i386__)) || (defined(_WIN32)) || defined(_M_IX86) + #define TARGET_BITS ARCH_32BIT +#endif + +#if defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) + #undef TARGET_BITS + #define TARGET_BITS ARCH_64BIT +#endif + + +#if !defined(TARGET_BITS) + #define TARGET_BITS ARCH_32BIT +#endif + + +#endif \ No newline at end of file diff --git a/include/util/unix/osdef.h b/include/util/unix/osdef.h new file mode 100644 index 00000000..8c0bf542 --- /dev/null +++ b/include/util/unix/osdef.h @@ -0,0 +1,47 @@ +#ifndef _OSDEF_H_ +#define _OSDEF_H_ + +#include +#include + +#define CALLBACK PASCAL +#define WINAPI CDECL +#define WINAPIV CDECL +#define APIENTRY WINAPI +#define APIPRIVATE CDECL +#ifdef _68K_ +#define PASCAL __pascal +#else +#define PASCAL +#endif +#elif _MSC_VER + +#ifndef WINAPI +#define WINAPI __stdcall +#endif + +#ifndef CALLBACK +#define CALLBACK __stdcall +#endif + +#ifndef WINAPIV +#define WINAPIV __cdecl +#endif + +#ifndef APIENTRY +#define APIENTRY WINAPI +#endif + + + +#ifndef APIPRIVATE +#define APIPRIVATE __stdcall +#endif + + +#ifndef PASCAL +#define PASCAL __stdcall +#endif + + +#endif diff --git a/include/util/unix/ossysdef.h b/include/util/unix/ossysdef.h new file mode 100644 index 00000000..7d4f557e --- /dev/null +++ b/include/util/unix/ossysdef.h @@ -0,0 +1,7 @@ +#ifndef _OSSYSDEF_H_ +#define _OSSYSDEF_H_ + +#include + + +#endif \ No newline at end of file diff --git a/include/util/util.h b/include/util/util.h index 3f814fc1..4fb2cc25 100644 --- a/include/util/util.h +++ b/include/util/util.h @@ -3,13 +3,18 @@ #include #include -#include -#include #include #include #include +#include +#include + +//dl +#include +#include +//debug #include #endif // !_UTIL_H_ \ No newline at end of file diff --git a/include/util/win/osdef.h b/include/util/win/osdef.h new file mode 100644 index 00000000..3ed70039 --- /dev/null +++ b/include/util/win/osdef.h @@ -0,0 +1,20 @@ +#ifndef _OSDEF_H_ +#define _OSDEF_H_ + + +#include +#include + +#pragma warning(disable:4996) +#define byint64 __int64 +#define byuint64 unsigned __int64 +#define FMT_I64D "%I64d" +#define FMT_I64U "%I64u" + +#ifndef _SSIZE_T_ +#define _SSIZE_T_ +typedef SSIZE_T ssize_t; +#endif // !_SSIZE_T_ + + +#endif diff --git a/include/util/win/ossysdef.h b/include/util/win/ossysdef.h new file mode 100644 index 00000000..7d4f557e --- /dev/null +++ b/include/util/win/ossysdef.h @@ -0,0 +1,7 @@ +#ifndef _OSSYSDEF_H_ +#define _OSSYSDEF_H_ + +#include + + +#endif \ No newline at end of file -- Gitee From 28968f2afaf838cd59252721a97879d6f643ace7 Mon Sep 17 00:00:00 2001 From: thinking Date: Thu, 22 Mar 2018 21:59:57 +0800 Subject: [PATCH 04/10] add linux semaphore --- include/util/common.hpp | 30 ++++++++++++++++++++++++++++++ include/util/core.hpp | 29 ----------------------------- include/util/posix/osdef.h | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/include/util/common.hpp b/include/util/common.hpp index cc8afdf8..2dd77002 100644 --- a/include/util/common.hpp +++ b/include/util/common.hpp @@ -120,5 +120,35 @@ +#ifdef __cplusplus + #ifndef EXTERN_C + #define EXTERN_C extern "C" + #endif +#else + #ifndef EXTERN_C + #define EXTERN_C extern + #endif +#endif + + +#ifdef __cplusplus + #define STDNOTHROW (std::nothrow) + #define Memory_Allocate new STDNOTHROW + #ifndef tstring + #ifdef _UNICODE + #define _T(x) L##x + #define tstring std::wstring + #else + #define tstring std::string + #define _T(x) x + #endif + #endif +#else + #define Memory_Allocate malloc + #define STDNOTHROW +#endif + + + #endif \ No newline at end of file diff --git a/include/util/core.hpp b/include/util/core.hpp index 8c68d225..5db7b19e 100644 --- a/include/util/core.hpp +++ b/include/util/core.hpp @@ -38,35 +38,6 @@ #endif - -#ifdef __cplusplus - #define Memory_Allocate new (std::nothrow) - - #ifndef EXTERN_C - #define EXTERN_C extern "C" - #endif - - #define STDNOTHROW (std::nothrow) - - #ifndef tstring - #ifdef _UNICODE - #define _T(x) L##x - #define tstring std::wstring - #else - #define tstring std::string - #define _T(x) x - #endif - #endif -#else - #define Memory_Allocate malloc - - #ifndef EXTERN_C - #define EXTERN_C extern "C" - #endif - - #define STDNOTHROW -#endif - #ifdef __GNUC__ #define MODULE_API HRESULT OS_VISIBILITY_DEFAULT #else diff --git a/include/util/posix/osdef.h b/include/util/posix/osdef.h index 04eef1d1..5b53e951 100644 --- a/include/util/posix/osdef.h +++ b/include/util/posix/osdef.h @@ -13,7 +13,7 @@ #include #include - #include +#include #define byint64 long long int #define byuint64 unsigned long long int -- Gitee From 443bb1ca5861f5e67d43f97d2b8ac2470d3f22f5 Mon Sep 17 00:00:00 2001 From: thinking Date: Fri, 23 Mar 2018 00:23:52 +0800 Subject: [PATCH 05/10] up singletion --- .gitignore | 1 + asynio/ioeventdef.h | 4 --- asynio/ioeventloop.h | 5 +++ asynio/iotcpbase.cpp | 2 +- asynio/iotcpbase.h | 2 ++ include/util/locksection.hpp | 1 + include/util/singletion.hpp | 65 ++++++++++++++++++------------------ 7 files changed, 43 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 235cfcbd..c5079f74 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ *.Tlog # VC project *.user +.vs diff --git a/asynio/ioeventdef.h b/asynio/ioeventdef.h index b59eca6d..b7f34350 100644 --- a/asynio/ioeventdef.h +++ b/asynio/ioeventdef.h @@ -3,10 +3,6 @@ #include "stdafx.h" - -#undef _WINSOCKAPI_ -#define _WINSOCKAPI_ - #include template diff --git a/asynio/ioeventloop.h b/asynio/ioeventloop.h index 3575523e..35b39674 100644 --- a/asynio/ioeventloop.h +++ b/asynio/ioeventloop.h @@ -13,6 +13,11 @@ public: virtual ~ioeventloop() { } + + static ioeventloop* Getioeventloop() { + return CSingletion::GetInstance(); + } + public: uv_loop_t* GetEv() { return uvloopbase; diff --git a/asynio/iotcpbase.cpp b/asynio/iotcpbase.cpp index d8b63559..d25de7ed 100644 --- a/asynio/iotcpbase.cpp +++ b/asynio/iotcpbase.cpp @@ -10,7 +10,7 @@ io_tcp_i::~io_tcp_i() { } int io_tcp_i::SockToIoEvent(os_sock_t sock) { tcphandler = (uv_tcp_t*)malloc(sizeof(uv_tcp_t)); - uv_tcp_init(GetEv(), tcphandler); + uv_tcp_init(ioeventloop::Getioeventloop()->GetEv(), tcphandler); return uv_tcp_open(tcphandler, sock); } int io_tcp_i::Connect() { diff --git a/asynio/iotcpbase.h b/asynio/iotcpbase.h index 63cc7d43..28aa7be9 100644 --- a/asynio/iotcpbase.h +++ b/asynio/iotcpbase.h @@ -2,6 +2,8 @@ #define _IOTCPBASE_H_ #include "iostreambase.h" +#include "ioeventloop.h" + class io_tcp_i : public io_stream_t { public: diff --git a/include/util/locksection.hpp b/include/util/locksection.hpp index d273d4a4..804eb70b 100644 --- a/include/util/locksection.hpp +++ b/include/util/locksection.hpp @@ -165,6 +165,7 @@ public: }; + /* template class CSingleInstance : public _TInterface diff --git a/include/util/singletion.hpp b/include/util/singletion.hpp index 8aa4e6f2..8c91f065 100644 --- a/include/util/singletion.hpp +++ b/include/util/singletion.hpp @@ -4,49 +4,50 @@ #include #include #include +using namespace util; -namespace util { -template -class CSingletion : public _TInterface +template < class _Type > +class CSingletion { -protected: - LONG m_dwRef; +public: + static _Type* GetInstance() { - inline ULONG Increment(long* p) - { - return lockadd(p); - } - inline ULONG Decrement(long* p) - { - return lockdel(p); - } + CStackAutoCSLock lock(s_lock); + if (0 == s_pInstance) + { + if (s_destroy) + { + return 0; + } + s_pInstance = new _Type; + } + return s_pInstance; -public: - CSingletion() - { - m_dwRef = 1L; - } - virtual ~CSingletion() - { - Decrement(&m_dwRef); } + static void DestroyInstance() { - virtual long AddRef() - { - return Increment(&m_dwRef); - } - virtual long ReleaseRef() - { - LONG l = Decrement(&m_dwRef); - if (l == 0) + CStackAutoCSLock lock(s_lock); + if (0 != s_pInstance) { - delete this; + delete s_pInstance; + s_pInstance = 0; + s_destroy = true; } - return l; } +protected: + CSingletion() {}; + virtual ~CSingletion() {}; +private: + static _Type* s_pInstance; + static bool s_destroy; + static CAutoCriticalSection s_lock; }; -} +////////////////////////////////////////////////////////////////////////// +template T* CSingletion::s_pInstance = 0; +template bool CSingletion::s_destroy = false; +template CAutoCriticalSection CSingletion::s_lock; +////////////////////////////////////////////////////////////////////////// #endif -- Gitee From 6402449477d6250a1e5fc909db2df0bf537bc459 Mon Sep 17 00:00:00 2001 From: thinking Date: Sat, 24 Mar 2018 01:12:54 +0800 Subject: [PATCH 06/10] up atomic and singletion --- CMakeLists.txt | 1 + asynio/stdafx.h | 5 +++++ comenv/innerlock.h | 41 ++++++++++++++++++++++++++---------- include/dlcom/comfunc.hpp | 12 +++++------ include/util/lockex.hpp | 11 ++++------ include/util/locksection.hpp | 27 ++++++++++++++++++++++++ include/util/singletion.hpp | 35 ++++++++++++++++++------------ 7 files changed, 95 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea478163..5b5a5c19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ else() message(FATAL_ERROR "unknown CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}") endif() +add_definitions(-std=c++11) message("lbycom Info") message("-- lbycom System = ${CMAKE_SYSTEM_NAME}") diff --git a/asynio/stdafx.h b/asynio/stdafx.h index 0f2c0d7f..a9b41c0e 100644 --- a/asynio/stdafx.h +++ b/asynio/stdafx.h @@ -17,4 +17,9 @@ using namespace by; #include #include + + + + + #endif \ No newline at end of file diff --git a/comenv/innerlock.h b/comenv/innerlock.h index d4186870..479cb1db 100644 --- a/comenv/innerlock.h +++ b/comenv/innerlock.h @@ -13,25 +13,44 @@ public: class CSrvCriticalSection { public: - void Lock() + CSrvCriticalSection() { - lockadd(&m_sec); +#ifndef __GNUC__ + InitializeCriticalSection(&m_sec); +#else + pthread_mutex_init(&m_sec, NULL); +#endif } - void Unlock() + ~CSrvCriticalSection() { - lockdel(&m_sec); +#ifndef __GNUC__ + DeleteCriticalSection(&m_sec); +#else + pthread_mutex_destroy(&m_sec); +#endif } - - CSrvCriticalSection() + + void Lock() { - lockinit(&m_sec); +#ifndef __GNUC__ + EnterCriticalSection(&m_sec); +#else + pthread_mutex_lock(&m_sec); +#endif } - ~CSrvCriticalSection() + void Unlock() { - lockuninit(&m_sec); +#ifndef __GNUC__ + LeaveCriticalSection(&m_sec); +#else + pthread_mutex_unlock(&m_sec); +#endif } - - long m_sec; +#ifndef __GNUC__ + CRITICAL_SECTION m_sec; +#else + pthread_mutex_t m_sec; +#endif }; diff --git a/include/dlcom/comfunc.hpp b/include/dlcom/comfunc.hpp index 3e752928..85265356 100644 --- a/include/dlcom/comfunc.hpp +++ b/include/dlcom/comfunc.hpp @@ -70,14 +70,14 @@ namespace by { #define ADDREF \ std_method_(ULONG, AddRef)() \ { \ - lockadd((LONG*)(LPVOID)&this->m_RefCount); \ + atomicadd((LONG*)(LPVOID)&this->m_RefCount); \ return this->m_RefCount; \ } \ #define RELEASE \ std_method_(ULONG, Release)() \ { \ - lockdel((LONG*)(LPVOID)&this->m_RefCount); \ + atomicdel((LONG*)(LPVOID)&this->m_RefCount); \ if(this->m_RefCount) \ return this->m_RefCount; \ delete this; \ @@ -95,14 +95,14 @@ namespace by { #define ADDREF_EX \ std_method_(ULONG, AddRef)() \ { \ - lockadd((LONG*)(LPVOID)&this->m_RefCount); \ + atomicadd((LONG*)(LPVOID)&this->m_RefCount); \ return this->m_RefCount; \ } \ #define RELEASE_EX \ std_method_(ULONG, Release)() \ { \ - lockdel((LONG*)(LPVOID)&this->m_RefCount); \ + atomicdel((LONG*)(LPVOID)&this->m_RefCount); \ if(this->m_RefCount) \ return this->m_RefCount; \ delete this; \ @@ -188,14 +188,14 @@ namespace by { #define ADDREF_NONDELEGATE \ std_method_(ULONG, AddRef_Nondelegate)() \ { \ - lockadd((LONG*)(LPVOID)&this->m_RefCount); \ + atomicadd((LONG*)(LPVOID)&this->m_RefCount); \ return this->m_RefCount; \ } \ #define RELEASE_NONDELEGATE \ std_method_(ULONG, Release_Nondelegate)() \ { \ - lockdel((LONG*)(LPVOID)&this->m_RefCount); \ + atomicdel((LONG*)(LPVOID)&this->m_RefCount); \ if(this->m_RefCount) \ return this->m_RefCount; \ delete this ; \ diff --git a/include/util/lockex.hpp b/include/util/lockex.hpp index a0a0f618..e87e882f 100644 --- a/include/util/lockex.hpp +++ b/include/util/lockex.hpp @@ -4,7 +4,7 @@ #include -inline static long lockadd(long* lpAddend){ +inline static long atomicadd(long* lpAddend){ #if (TARGET_OS == OS_WINDOWS) return InterlockedIncrement(lpAddend); #elif (TARGET_OS == OS_POSIX) @@ -12,7 +12,7 @@ inline static long lockadd(long* lpAddend){ #endif } -inline static long lockdel(long* lpAddend){ +inline static long atomicdel(long* lpAddend){ #if (TARGET_OS == OS_WINDOWS) return InterlockedDecrement(lpAddend); #elif (TARGET_OS == OS_POSIX) @@ -20,14 +20,11 @@ inline static long lockdel(long* lpAddend){ #endif } -inline static void lockinit(long* lpAddend) { +inline static void atomicinit(long* lpAddend) { *lpAddend = 0; } - -inline static void lockuninit(long* lpAddend) { +inline static void atomicuninit(long* lpAddend) { *lpAddend = 0; } - - #endif \ No newline at end of file diff --git a/include/util/locksection.hpp b/include/util/locksection.hpp index 804eb70b..0a980528 100644 --- a/include/util/locksection.hpp +++ b/include/util/locksection.hpp @@ -28,6 +28,33 @@ namespace util { +/* +class spin11_lock +{ + std::atomic m_spin; +public: + spin11_lock() : m_spin(0) { + + } + ~spin11_lock() { + //assert(m_spin.load(memory_order_relaxed) == 0); + } + + void lock() + { + unsigned int nCur; + do { + nCur = 0; + } while (!m_spin.compare_exchange_weak(nCur, 1, memory_order_acquire)); + + } + void unlock() + { + m_spin.store(0, memory_order_release); + } +}; +*/ + class CNullCriticalSection { diff --git a/include/util/singletion.hpp b/include/util/singletion.hpp index 8c91f065..3a74644c 100644 --- a/include/util/singletion.hpp +++ b/include/util/singletion.hpp @@ -6,48 +6,57 @@ #include using namespace util; + +#ifdef __cplusplus + +#include + template < class _Type > -class CSingletion +class CPP_NO_VTABLE CSingletion { public: static _Type* GetInstance() { - CStackAutoCSLock lock(s_lock); - if (0 == s_pInstance) - { - if (s_destroy) - { - return 0; - } + if (NULL == s_pInstance) { + s_pInstance = new _Type; } + s_ref.fetch_add(1, std::memory_order_release); return s_pInstance; } static void DestroyInstance() { - CStackAutoCSLock lock(s_lock); - if (0 != s_pInstance) + s_ref.fetch_sub(1, std::memory_order_release); + + if (s_ref.load(std::memory_order_acquire) == 0) { delete s_pInstance; s_pInstance = 0; s_destroy = true; } + } protected: CSingletion() {}; virtual ~CSingletion() {}; + +//////////////////////////////////// + private: static _Type* s_pInstance; static bool s_destroy; - static CAutoCriticalSection s_lock; + static std::atomic s_ref; }; ////////////////////////////////////////////////////////////////////////// template T* CSingletion::s_pInstance = 0; -template bool CSingletion::s_destroy = false; -template CAutoCriticalSection CSingletion::s_lock; +template std::atomic CSingletion::s_ref = 0; ////////////////////////////////////////////////////////////////////////// +#endif + + + #endif -- Gitee From b229d74d8f34c231d249f5342a1be7dba237252c Mon Sep 17 00:00:00 2001 From: thinking Date: Sat, 24 Mar 2018 15:29:13 +0800 Subject: [PATCH 07/10] linux compile --- 3rd/libuv/m4/libuv-check-flags.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rd/libuv/m4/libuv-check-flags.m4 b/3rd/libuv/m4/libuv-check-flags.m4 index 59c30635..81f474c3 100644 --- a/3rd/libuv/m4/libuv-check-flags.m4 +++ b/3rd/libuv/m4/libuv-check-flags.m4 @@ -316,4 +316,4 @@ AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [ AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned], [Define the highest alignment supported]) fi -]) \ No newline at end of file +]) -- Gitee From 60baa38bf3e58986ce1381ec87fdfa5ac081d79e Mon Sep 17 00:00:00 2001 From: thinking Date: Sat, 24 Mar 2018 17:10:31 +0800 Subject: [PATCH 08/10] singleton up --- CMakeLists.txt | 2 +- include/util/singletion.hpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b5a5c19..efed3296 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ message("-- lbycom Compile = ${CMAKE_BUILD_TYPE}") add_subdirectory(main) add_subdirectory(comenv) add_subdirectory(infoanalysis) -#add_subdirectory(asynio) +add_subdirectory(asynio) add_subdirectory(sshchannel) #add_subdirectory(adapterjs) #add_subdirectory(adapterlua) diff --git a/include/util/singletion.hpp b/include/util/singletion.hpp index 3a74644c..b44d79d1 100644 --- a/include/util/singletion.hpp +++ b/include/util/singletion.hpp @@ -33,7 +33,6 @@ public: { delete s_pInstance; s_pInstance = 0; - s_destroy = true; } } @@ -46,13 +45,12 @@ protected: private: static _Type* s_pInstance; - static bool s_destroy; static std::atomic s_ref; }; ////////////////////////////////////////////////////////////////////////// template T* CSingletion::s_pInstance = 0; -template std::atomic CSingletion::s_ref = 0; +template std::atomic CSingletion::s_ref(0); ////////////////////////////////////////////////////////////////////////// #endif -- Gitee From b6ff1310477ff3cc7e886a5ed0f6abdb21702564 Mon Sep 17 00:00:00 2001 From: thinking Date: Sun, 25 Mar 2018 22:09:25 +0800 Subject: [PATCH 09/10] del atmoic function --- include/util/singletion.hpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/include/util/singletion.hpp b/include/util/singletion.hpp index b44d79d1..deaa7e83 100644 --- a/include/util/singletion.hpp +++ b/include/util/singletion.hpp @@ -9,7 +9,7 @@ using namespace util; #ifdef __cplusplus -#include +//#include template < class _Type > class CPP_NO_VTABLE CSingletion @@ -21,15 +21,19 @@ public: s_pInstance = new _Type; } - s_ref.fetch_add(1, std::memory_order_release); + //s_ref.fetch_add(1, std::memory_order_release); + + atomicadd(&s_ref); + return s_pInstance; } static void DestroyInstance() { - s_ref.fetch_sub(1, std::memory_order_release); - - if (s_ref.load(std::memory_order_acquire) == 0) + //s_ref.fetch_sub(1, std::memory_order_release); + atomicdel(&s_ref); + //if (s_ref.load(std::memory_order_acquire) == 0) + if (!s_ref) { delete s_pInstance; s_pInstance = 0; @@ -45,12 +49,14 @@ protected: private: static _Type* s_pInstance; - static std::atomic s_ref; + //static std::atomic_long s_ref; + static long s_ref; }; ////////////////////////////////////////////////////////////////////////// -template T* CSingletion::s_pInstance = 0; -template std::atomic CSingletion::s_ref(0); +template T* CSingletion::s_pInstance = 0; +//template std::atomic_long CSingletion::s_ref(0); +template long CSingletion::s_ref = 0; ////////////////////////////////////////////////////////////////////////// #endif -- Gitee From 598e4d312e3aadafef9ce2e51bb50afb90226ac5 Mon Sep 17 00:00:00 2001 From: thinking Date: Sun, 25 Mar 2018 23:43:31 +0800 Subject: [PATCH 10/10] rename openmd to loadlib --- comenv/objectloader.cpp | 10 +++++----- include/util/calldll.hpp | 10 +++++----- include/util/callfunc.hpp | 8 +++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/comenv/objectloader.cpp b/comenv/objectloader.cpp index b7900fc1..7b630598 100644 --- a/comenv/objectloader.cpp +++ b/comenv/objectloader.cpp @@ -27,7 +27,7 @@ std_method_impl CObjectLoader::Register(const CLSID& rclsid, LPCTSTR filename, L { if(it->second.hModule) { - closemd(it->second.hModule); + closelib(it->second.hModule); } } else @@ -61,9 +61,9 @@ std_method_impl CObjectLoader::CreateInstance(IModuleBase *prot,const CLSID& rcl retrtpv(m_mapCls.end() != it, E_INVALIDARG); if(!it->second.hModule) { - it->second.hModule = openmd((TCHAR*)it->second.filename.c_str()); + it->second.hModule = loadlib((TCHAR*)it->second.filename.c_str()); retrtpv(it->second.hModule, E_UNEXPECTED); - it->second.pfnGetClsObj = (PFNGetClsObj)openfunc(it->second.hModule, (char*)"DllGetClassObject"); + it->second.pfnGetClsObj = (PFNGetClsObj)libfunc(it->second.hModule, (char*)"DllGetClassObject"); } retrtpv(it->second.pfnGetClsObj, E_UNEXPECTED); _lComPtr pfac; @@ -80,7 +80,7 @@ std_method_impl CObjectLoader::Revoke(const CLSID& rclsid) retrtpv(m_mapCls.end() != it, S_FALSE); if(it->second.hModule && it->second.hModule != (HMODULE)-1) { - closemd(it->second.hModule); + closelib(it->second.hModule); } m_mapCls.erase(it); @@ -94,7 +94,7 @@ std_method_impl CObjectLoader::FreeUnusedLibraries() { if(it->second.hModule && it->second.hModule !=(HMODULE) -1) { - closemd(it->second.hModule); + closelib(it->second.hModule); it->second.hModule = 0; } } diff --git a/include/util/calldll.hpp b/include/util/calldll.hpp index 3569610c..d8c473ff 100644 --- a/include/util/calldll.hpp +++ b/include/util/calldll.hpp @@ -65,11 +65,11 @@ namespace util { if(szPath[tstring_strlen(szPath)-1] != _T('\\')) tstring_strcat(buf, _T("\\")); tstring_strcat(buf, m_szModuleName); - m_hMod = openmd(buf); - hMod = m_hMod; + m_hMod = loadlib(buf); + hMod = m_hMod; } else - m_hMod = openmd(m_szModuleName); + m_hMod = loadlib(m_szModuleName); hMod = m_hMod; } if (!hMod) @@ -78,7 +78,7 @@ namespace util { { while(string_stricmp(pFunDesc->pFunName,"null") != 0) { - void *p = openfunc(hMod,pFunDesc->pFunName); + void *p = libfunc(hMod,pFunDesc->pFunName); //*(void**)(((char*)this)+pFunDesc->uOffFun)=p; setfuncaddress(pFunDesc->uOffFun,p); @@ -99,7 +99,7 @@ namespace util { { if(m_hMod) { - closemd(m_hMod); + closelib(m_hMod); } m_hMod = NULL; //InitIAT(); diff --git a/include/util/callfunc.hpp b/include/util/callfunc.hpp index d008b233..239c41cb 100644 --- a/include/util/callfunc.hpp +++ b/include/util/callfunc.hpp @@ -10,18 +10,16 @@ namespace util { - inline static HMODULE openmd(TCHAR* path,int flag = RTLD_LAZY) { + inline static HMODULE loadlib(TCHAR* path,int flag = RTLD_LAZY) { #if (TARGET_OS == OS_WINDOWS) return ::LoadLibraryW(path); #elif (TARGET_OS == OS_POSIX) //init function ??? return dlopen(path,flag); #endif - - } - inline static void* openfunc(HMODULE handler,char* sym){ + inline static void* libfunc(HMODULE handler,char* sym){ #if (TARGET_OS == OS_WINDOWS) return ::GetProcAddress(handler,sym); #elif (TARGET_OS == OS_POSIX) @@ -34,7 +32,7 @@ namespace util { return pFunc; #endif } - inline static int closemd(HMODULE handler){ + inline static int closelib(HMODULE handler){ #if (TARGET_OS == OS_WINDOWS) return ::FreeLibrary(handler); #elif (TARGET_OS == OS_POSIX) -- Gitee