SMOOTH LIKE BUTTER

This commit is contained in:
malloc 2019-01-03 15:37:41 -06:00
parent eaac4f0948
commit 855cdc1344
4 changed files with 35 additions and 14 deletions

View file

@ -18,7 +18,7 @@ install(TARGETS server RUNTIME DESTINATION bin/server)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
target_link_libraries(server wsock32 ws2_32) target_link_libraries(server wsock32 ws2_32)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
target_link_libraries(server dl pthread nsl resolv) target_link_libraries(server pthread nsl resolv)
else() else()
target_link_libraries(server dl pthread socket nsl resolv) target_link_libraries(server pthread socket nsl resolv)
endif() endif()

View file

@ -2,7 +2,7 @@
#define GLV_SOCK_TCP_H #define GLV_SOCK_TCP_H
#ifdef _WIN32 #ifdef _WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#ifdef __MINGW32__ #ifdef __MINGW32__
#undef _WIN32_WINNT #undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WIN8 #define _WIN32_WINNT _WIN32_WINNT_WIN8
@ -10,11 +10,8 @@
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
typedef GLV_SOCK_T SOCKET; typedef SOCKET glv_sock_t;
typedef GLV_ADDR_T SOCKADDR_ typedef SOCKADDR_IN glv_addr_t;
#define GLV_SOCK_T SOCKET
#define GLV_ADDR_T SOCKADDR_IN
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
@ -25,8 +22,8 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#define GLV_SOCK_T int typedef int glv_sock_t;
#define GLV_ADDR_T struct sockaddr_in typedef struct sockaddr_in glv_addr_t;
#endif #endif
#include <stdint.h> #include <stdint.h>
@ -35,14 +32,16 @@
#define GLV_TCP_FLAG_NBIO 2 #define GLV_TCP_FLAG_NBIO 2
typedef struct { typedef struct {
glv_sock_t socket;
glv_addr_t addr;
uint32_t flags; uint32_t flags;
} tcp_t; } glv_tcp_t;
tcp_t* tcp_create_server(); glv_tcp_t* glv_tcp_create_server();
tcp_t* tcp_create_client(); glv_tcp_t* glv_tcp_create_client();
void tcp_destroy(tcp_t* socket); void glv_tcp_destroy(glv_tcp_t* socket);
#endif #endif

View file

@ -1,2 +1,4 @@
#ifdef _WIN32
#include "tcp.h" #include "tcp.h"
#endif

View file

@ -1,4 +1,24 @@
#ifndef GLV_UTIL_THREAD_H #ifndef GLV_UTIL_THREAD_H
#define GLV_UTIL_THREAD_H #define GLV_UTIL_THREAD_H
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#ifdef __MINGW32__
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WIN8
#endif
#include <windows.h>
typedef HANDLE glv_thread_t;
typedef HANDLE glv_mutex_t;
#else
#include <pthread.h>
typedef pthread_t glv_thread_t;
typedef pthread_mutex_t glv_mutex_t;
#endif
glv_thread_t* glv_thread_create();
void glv_thread_destroy(glv_thread_t* thread);
#endif #endif