From 2a2ae674e69072c2dccebe6be80fdf5bd6274ac8 Mon Sep 17 00:00:00 2001 From: zzy <2450266535@qq.com> Date: Sun, 22 Oct 2023 21:43:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ ssocket.h | 44 +++----------------------------------------- sysenv.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ tthread.h | 36 ++++++++++++++++++++++++++++++++++++ version.txt | 5 ++++- 5 files changed, 90 insertions(+), 42 deletions(-) create mode 100644 sysenv.h create mode 100644 tthread.h diff --git a/.gitignore b/.gitignore index c3a1c25..7000632 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ !README.txt !version.txt !ssocket.h +!tthread.h +!sysenv.h !*/ !test/client/client.c !test/client/CMakeLists.txt diff --git a/ssocket.h b/ssocket.h index 481226b..3d7786e 100644 --- a/ssocket.h +++ b/ssocket.h @@ -7,47 +7,7 @@ #define SSOCKET_VERSION_MAJOR 1 #define SSOCKET_VERSION_MINOR 0 #define SSOCKET_VERSION_PATCH 2 - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) - #define _OS_WIN 1 - //define something for Windows (32-bit and 64-bit, this part is common) - #ifdef _WIN64 - #define _OS_WIN64 1 - //define something for Windows (64-bit only) - #else - #define _OS_WIN32 1 - //define something for Windows (32-bit only) - #endif -#elif __APPLE__ - #define _OS_APPLE 1 - #include - #if TARGET_IPHONE_SIMULATOR - #define _OS_APPLE_SIM 1 - // iOS, tvOS, or watchOS Simulator - #elif TARGET_OS_MACCATALYST - #define _OS_APPLE_CATA 1 - // Mac's Catalyst (ports iOS API into Mac, like UIKit). - #elif TARGET_OS_IPHONE - #define _OS_APPLE_PHO 1 - // iOS, tvOS, or watchOS device - #elif TARGET_OS_MAC - #define _OS_APPLE_MAC 1 - // Other kinds of Apple platforms - #else - # error "Unknown Apple platform" - #endif -#elif __linux__ -#define _OS_LINUX 1 - // linux -#elif __unix__ // all unices not caught above -#define _OS_UNIX 1 - // Unix -#elif defined(_POSIX_VERSION) -#define _OS_POSIX 1 - // POSIX -#else -# error "Unknown compiler" -#endif +#include "sysenv.h" #if _OS_WIN #define WIN_PART 1 @@ -73,6 +33,8 @@ //#define INVALID_SOCKET (SOCKET)(~0) #endif +#include "tthread.h" + #ifndef ZZY_SLEEP #define ZZY_SLEEP #if WIN_PART diff --git a/sysenv.h b/sysenv.h new file mode 100644 index 0000000..85c79b5 --- /dev/null +++ b/sysenv.h @@ -0,0 +1,45 @@ +#ifndef _SYSENV_H_ +#define _SYSENV_H_ + +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) + #define _OS_WIN 1 + //define something for Windows (32-bit and 64-bit, this part is common) + #ifdef _WIN64 + #define _OS_WIN64 1 + //define something for Windows (64-bit only) + #else + #define _OS_WIN32 1 + //define something for Windows (32-bit only) + #endif +#elif __APPLE__ + #define _OS_APPLE 1 + #include + #if TARGET_IPHONE_SIMULATOR + #define _OS_APPLE_SIM 1 + // iOS, tvOS, or watchOS Simulator + #elif TARGET_OS_MACCATALYST + #define _OS_APPLE_CATA 1 + // Mac's Catalyst (ports iOS API into Mac, like UIKit). + #elif TARGET_OS_IPHONE + #define _OS_APPLE_PHO 1 + // iOS, tvOS, or watchOS device + #elif TARGET_OS_MAC + #define _OS_APPLE_MAC 1 + // Other kinds of Apple platforms + #else + # error "Unknown Apple platform" + #endif +#elif __linux__ +#define _OS_LINUX 1 + // linux +#elif __unix__ // all unices not caught above +#define _OS_UNIX 1 + // Unix +#elif defined(_POSIX_VERSION) +#define _OS_POSIX 1 + // POSIX +#else +# error "Unknown compiler" +#endif + +#endif //_SYSENV_H_ \ No newline at end of file diff --git a/tthread.h b/tthread.h new file mode 100644 index 0000000..56c4696 --- /dev/null +++ b/tthread.h @@ -0,0 +1,36 @@ +#ifndef _TTHERAD_H_ +#define _TTHREAD_H_ + +#include "sysenv.h" +#if _OS_WIN +#include +#define TID LPDWORD + +#elif _OS_LINUX +#include +#include +#include +#define TID pthread_t + +#else +#error "Not Supported Operator System" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +static inline void tthread_create(TID* tid,void(*thread_func)(void*), void* data) { +#if _OS_WIN + CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_func, data, 0, tid); +#elif _OS_LINUX + pthread_create(tid, 0, (void*(*)(void*))thread_func, data); +#endif +} + +#ifdef __cplusplus +} +#endif + +#endif //_TTHREAD_H_ \ No newline at end of file diff --git a/version.txt b/version.txt index 3ca5d73..4227e71 100644 --- a/version.txt +++ b/version.txt @@ -4,4 +4,7 @@ v1.0.2 ssocket 使用getaddrinfo重写部分内容,为未来兼容tcp/udp-ipv4/ipv6做准备 添加make_sock,make_sock_tcp4,make_sock_tcp6,make_sock_udp4,make_sock_udp6函数 添加若干内置函数(以_func形式) - 兼容老版本 \ No newline at end of file + 兼容老版本 +v1.0.3 ssocket + 使用多头文件分离的方法将系统环境,线程,套接字分成三个文档 + 暂时兼容老版本,将在下个版本取消对前版本的兼容性 \ No newline at end of file