PACK() macro
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include "Autoarr.h"
|
||||
|
||||
Autoarr_define(uint8)
|
||||
Autoarr_define(int8)
|
||||
Autoarr_define(uint16)
|
||||
Autoarr_define(int16)
|
||||
Autoarr_define(uint8);
|
||||
Autoarr_define(int8);
|
||||
Autoarr_define(uint16);
|
||||
Autoarr_define(int16);
|
||||
Autoarr_define(uint32);
|
||||
Autoarr_define(int32);
|
||||
Autoarr_define(uint64);
|
||||
|
||||
0
src/Network/README.md
Normal file
0
src/Network/README.md
Normal file
@@ -19,7 +19,7 @@ typedef union knIPV4Address {
|
||||
///@return Maybe<uint64> as Maybe<knIPV4Address>
|
||||
Maybe knIPV4Address_fromStr(char* addrStr);
|
||||
|
||||
typedef struct __attribute__((__packed__)) knIPV4Endpoint {
|
||||
typedef struct knIPV4Endpoint {
|
||||
knIPV4Address address;
|
||||
knPort port;
|
||||
} knIPV4Endpoint;
|
||||
|
||||
@@ -10,9 +10,9 @@ extern "C" {
|
||||
#define KNPAC_MAX_DATA_SIZE (65535-sizeof(knPackage)+sizeof(uint8*))
|
||||
|
||||
|
||||
typedef enum __attribute__((__packed__)) knPacVersion {
|
||||
typedef enum knPacVersion PACK({
|
||||
knPac_V1
|
||||
} knPacVersion;
|
||||
}) knPacVersion;
|
||||
|
||||
static const char knPacHeader[5]={'k','n','p','a','c'};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "stdSocketHeaders.h"
|
||||
|
||||
|
||||
Maybe knSocket_open(knSockType sockType){
|
||||
Maybe knSocket_open(knSocketType sockType){
|
||||
knSocket* newSocket=malloc(sizeof(knSocket));
|
||||
newSocket->type=sockType;
|
||||
newSocket->channels=NULL;
|
||||
@@ -13,12 +13,12 @@ Maybe knSocket_open(knSockType sockType){
|
||||
default:
|
||||
safethrow("unknown socket type", free(newSocket));
|
||||
break;
|
||||
case knSockType_TCP:
|
||||
case knSocketType_TCP:
|
||||
newSocket->socketfd=socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(newSocket->socketfd==-1)
|
||||
safethrow("can't create TCP socket", free(newSocket));
|
||||
break;
|
||||
case knSockType_UDP:
|
||||
case knSocketType_UDP:
|
||||
newSocket->socketfd=socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(newSocket->socketfd==-1)
|
||||
safethrow("can't create UDP socket", free(newSocket));
|
||||
|
||||
@@ -9,12 +9,12 @@ extern "C" {
|
||||
#include "knPackage.h"
|
||||
|
||||
|
||||
typedef enum __attribute__((__packed__)) knSockType {
|
||||
knSockType_TCP, knSockType_UDP
|
||||
} knSockType;
|
||||
typedef enum knSocketType PACK({
|
||||
knSocketType_TCP, knSocketType_UDP
|
||||
}) knSocketType;
|
||||
|
||||
typedef struct knSocket {
|
||||
knSockType type;
|
||||
knSocketType type;
|
||||
uint16 channelsAmount;
|
||||
knChannel* channels;
|
||||
int64 socketfd;
|
||||
@@ -23,7 +23,7 @@ typedef struct knSocket {
|
||||
} knSocket;
|
||||
|
||||
///@return Maybe<knSocket*> new socket
|
||||
Maybe knSocket_open(knSockType sockType);
|
||||
Maybe knSocket_open(knSocketType sockType);
|
||||
|
||||
///@return Maybe<void> error or nothing
|
||||
Maybe knSocket_close(knSocket* socket);
|
||||
|
||||
@@ -13,7 +13,8 @@ extern "C" {
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if __cplusplus
|
||||
|
||||
@@ -11,7 +11,6 @@ extern "C" {
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
#include <setjmp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define dbg(N) printf("\e[95m%d\n",N)
|
||||
@@ -36,6 +35,7 @@ extern "C" {
|
||||
#pragma GCC error "unknown compiler"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define IFWIN(YES, NO) YES
|
||||
#define IFMSC(YES, NO) YES
|
||||
@@ -53,6 +53,15 @@ extern "C" {
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define PACK(...) __VA_ARGS__ __attribute__((__packed__))
|
||||
#elif defined(_MSC_VER)
|
||||
#define PACK(...) __pragma(pack(push, 1)) __VA_ARGS__ __pragma(pack(pop))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -16,7 +16,7 @@ typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
typedef enum __attribute__((__packed__)) my_type {
|
||||
typedef enum my_type PACK({
|
||||
Null, Float32, Float64, Char, Bool,
|
||||
UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64,
|
||||
UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr,
|
||||
@@ -25,7 +25,7 @@ typedef enum __attribute__((__packed__)) my_type {
|
||||
AutoarrInt8Ptr, AutoarrUInt8Ptr, AutoarrInt16Ptr, AutoarrUInt16Ptr,
|
||||
AutoarrInt32Ptr, AutoarrUInt32Ptr, AutoarrInt64Ptr, AutoarrUInt64Ptr,
|
||||
AutoarrUnitypePtr, AutoarrKVPairPtr, knSocketPtr
|
||||
} my_type;
|
||||
}) my_type;
|
||||
#define my_type_last knSocketPtr
|
||||
|
||||
const char* my_type_name(my_type t);
|
||||
|
||||
Reference in New Issue
Block a user