dev 1.0.5 linux

This commit is contained in:
zzy-linux 2023-11-04 13:39:50 +08:00
parent 4c33b6442e
commit 4f8a389ce3
6 changed files with 26 additions and 18 deletions

View File

@ -107,6 +107,7 @@ static inline int sock_connect(SOCKET sock, const char* connect_ip, unsigned sho
static inline int sock_bind(SOCKET sock, const char* server_ip, unsigned short port); static inline int sock_bind(SOCKET sock, const char* server_ip, unsigned short port);
static inline int sock_bindlisten(SOCKET sock, const char* server_ip, unsigned short port); static inline int sock_bindlisten(SOCKET sock, const char* server_ip, unsigned short port);
static inline int sock_accpet(SOCKET sock, SOCKET* client, char** accept_ip, unsigned short* port); static inline int sock_accpet(SOCKET sock, SOCKET* client, char** accept_ip, unsigned short* port);
static inline int _sock(SOCKET* sock, int af, int type);
static inline int make_sock_tcp4(SOCKET* sock) { return _sock(sock, AF_INET, SOCK_STREAM); } static inline int make_sock_tcp4(SOCKET* sock) { return _sock(sock, AF_INET, SOCK_STREAM); }
static inline int make_sock_tcp6(SOCKET* sock) { return _sock(sock, AF_INET6, SOCK_STREAM); } static inline int make_sock_tcp6(SOCKET* sock) { return _sock(sock, AF_INET6, SOCK_STREAM); }
static inline int make_sock_udp4(SOCKET* sock) { return _sock(sock, AF_INET, SOCK_DGRAM); } static inline int make_sock_udp4(SOCKET* sock) { return _sock(sock, AF_INET, SOCK_DGRAM); }
@ -119,7 +120,6 @@ static inline int _connect(SOCKET sock, struct addrinfo* resaddr);
static inline int _bind(SOCKET sock, struct addrinfo* resaddr); static inline int _bind(SOCKET sock, struct addrinfo* resaddr);
static inline int _bindlisten(SOCKET sock, struct addrinfo* resaddr); static inline int _bindlisten(SOCKET sock, struct addrinfo* resaddr);
static inline int _accept(SOCKET sock, SOCKET* client, struct addrinfo* inf); static inline int _accept(SOCKET sock, SOCKET* client, struct addrinfo* inf);
static inline int _sock(SOCKET* sock, int af, int type);
//not recommand and it will be remove //not recommand and it will be remove
static inline int make_sock(SOCKET* sock) { return make_sock_tcp4(sock); }; static inline int make_sock(SOCKET* sock) { return make_sock_tcp4(sock); };

View File

@ -3,23 +3,22 @@
#include <string.h> #include <string.h>
#if _OS_WIN #if _OS_WIN
#elif _OS_LINUX
#include <strings.h>
#else
#error "Not Supported Operator System"
#endif
#ifndef strcasecmp #ifndef strcasecmp
#define strcasecmp _stricmp #define strcasecmp _stricmp
#endif #endif
#ifndef strncasecmp #ifndef strncasecmp
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#endif #endif
#elif _OS_LINUX
#include <strings.h>
#else
#error "Not Supported Operator System"
#endif
#define INI_BUFFER_SIZE 512 #define INI_BUFFER_SIZE 512
inline INICHAR* _ini_skip_leading(const INICHAR* str) static inline INICHAR* _ini_skip_leading(const INICHAR* str)
{ {
assert(str != NULL); assert(str != NULL);
while ('\0' < *str && *str <= ' ') while ('\0' < *str && *str <= ' ')
@ -27,7 +26,7 @@ inline INICHAR* _ini_skip_leading(const INICHAR* str)
return (INICHAR*)str; return (INICHAR*)str;
} }
inline INICHAR* _ini_skip_trailing(const INICHAR* str, const INICHAR* base) static inline INICHAR* _ini_skip_trailing(const INICHAR* str, const INICHAR* base)
{ {
assert(str != NULL); assert(str != NULL);
assert(base != NULL); assert(base != NULL);
@ -36,7 +35,7 @@ inline INICHAR* _ini_skip_trailing(const INICHAR* str, const INICHAR* base)
return (INICHAR*)str; return (INICHAR*)str;
} }
inline INICHAR* _ini_str_skip_trailing(INICHAR* str) static inline INICHAR* _ini_str_skip_trailing(INICHAR* str)
{ {
INICHAR* ptr = _ini_skip_trailing(strchr(str, '\0'), str); INICHAR* ptr = _ini_skip_trailing(strchr(str, '\0'), str);
assert(ptr != NULL); assert(ptr != NULL);

View File

@ -4,7 +4,16 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#if _OS_WIN
#define LOG_COLOR(code) \033[##code##m #define LOG_COLOR(code) \033[##code##m
#elif _OS_LINUX
#define LOG_COLOR(code) \x1b\x5b##code##m
#else
#error "Not Supported Operator System"
#endif
#define LOG_COLOR_TRACE LOG_COLOR(94) #define LOG_COLOR_TRACE LOG_COLOR(94)
#define LOG_COLOR_DEBUG LOG_COLOR(36) #define LOG_COLOR_DEBUG LOG_COLOR(36)
#define LOG_COLOR_INFO LOG_COLOR(32) #define LOG_COLOR_INFO LOG_COLOR(32)

View File

@ -2,13 +2,13 @@ cmake_minimum_required(VERSION 3.22.1)
project(proj) project(proj)
set(EXECUTABLE_OUTPUT_PATH ../../) set(EXECUTABLE_OUTPUT_PATH ../)
set(C_STANDARD 99) set(C_STANDARD 99)
set(C_STANDARD_REQUIRED TRUE) set(C_STANDARD_REQUIRED TRUE)
set(C_EXTENSIONS FALSE) set(C_EXTENSIONS FALSE)
add_subdirectory(server_proj server) add_subdirectory(./server_proj server)
add_subdirectory(client_proj client) add_subdirectory(./client_proj client)
add_subdirectory(../../ zzylib) add_subdirectory(../../ zzylib)
# cmake .. # cmake ..
# cmake --build . # cmake --build .

View File

@ -51,7 +51,7 @@ void receive_message(void* param)
} }
void end(void) { void end(void) {
shutdown(cfd, SHUT_WD); shutdown(cfd, SHUT_WR);
close_sock(cfd); close_sock(cfd);
} }
@ -99,7 +99,7 @@ CONNECT:
log_head_info_ex(buf, BUFFER_SIZE, "command", g_mask); log_head_info_ex(buf, BUFFER_SIZE, "command", g_mask);
tprintf(&std_mutex, buf); tprintf(&std_mutex, buf);
tprintf(&std_mutex, "client exit... press enter to continue\n"); tprintf(&std_mutex, "client exit... press enter to continue\n");
shutdown(cfd, SHUT_WD); shutdown(cfd, SHUT_WR);
if(getchar()); if(getchar());
exit(-1); exit(-1);
} }

View File

@ -63,7 +63,7 @@ void receive_message(void* param)
} }
log_head_info_ex(buf, BUFFER_SIZE, "receive", g_mask); log_head_info_ex(buf, BUFFER_SIZE, "receive", g_mask);
tprintf(&std_mutex, buf); tprintf(&std_mutex, buf);
shutdown(sock, SHUT_WD); shutdown(sock, SHUT_WR);
tprintf(&std_mutex, "socket <%d> exit\n", sock); tprintf(&std_mutex, "socket <%d> exit\n", sock);
for(int i = 0; i < CLIENT_SIZE; i++) { for(int i = 0; i < CLIENT_SIZE; i++) {
if(cfds[i] == sock) { if(cfds[i] == sock) {
@ -118,7 +118,7 @@ void acceptfunc(void* param) {
} }
void end(void) { void end(void) {
shutdown(sfd, SHUT_WD); shutdown(sfd, SHUT_WR);
close_sock(sfd); close_sock(sfd);
for (int i = 0; i < CLIENT_SIZE; i++) { for (int i = 0; i < CLIENT_SIZE; i++) {
if (cfds[i] != 0) { if (cfds[i] != 0) {