|
version 1.16.32.2, 2019/12/18 20:00:17
|
version 1.32.4.1, 2026/07/29 01:02:05
|
|
Line 12 terms:
|
Line 12 terms:
|
| All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
|
| Copyright 2004 - 2019 | Copyright 2004 - 2026 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
|
| Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
|
Line 47 SUCH DAMAGE.
|
Line 47 SUCH DAMAGE.
|
| #define __ELWIX_H |
#define __ELWIX_H |
| |
|
| |
|
| |
#include <stdio.h> |
| #include <assert.h> |
#include <assert.h> |
| #include <syslog.h> |
#include <syslog.h> |
| #include <stdarg.h> |
#include <stdarg.h> |
| |
#include <stdalign.h> |
| #include <sys/types.h> |
#include <sys/types.h> |
| #include <sys/param.h> |
#include <sys/param.h> |
| #include <sys/socket.h> |
#include <sys/socket.h> |
| #include <sys/un.h> |
#include <sys/un.h> |
| |
#ifndef __cplusplus |
| |
#include <stdatomic.h> |
| |
#else |
| |
#include <atomic> |
| |
#define _Atomic(X) std::atomic<X> |
| |
#endif |
| #ifndef __linux__ |
#ifndef __linux__ |
| #include <sys/limits.h> |
#include <sys/limits.h> |
| #include <sys/endian.h> |
#include <sys/endian.h> |
|
Line 79 SUCH DAMAGE.
|
Line 87 SUCH DAMAGE.
|
| #include <elwix/apack.h> |
#include <elwix/apack.h> |
| #include <elwix/apio.h> |
#include <elwix/apio.h> |
| #include <elwix/ajson.h> |
#include <elwix/ajson.h> |
| |
#include <elwix/aiov.h> |
| |
#include <elwix/aindex.h> |
| |
#include <elwix/aring.h> |
| |
#include <elwix/auuid.h> |
| |
|
| |
|
| #ifndef STRSIZ |
#ifndef STRSIZ |
|
Line 159 SUCH DAMAGE.
|
Line 171 SUCH DAMAGE.
|
| #define powerof2(x) ((((x) - 1) & (x)) == 0) |
#define powerof2(x) ((((x) - 1) & (x)) == 0) |
| #endif |
#endif |
| |
|
| |
/* timespec helpers */ |
| |
#ifndef TIMEVAL_TO_TIMESPEC |
| |
#define TIMEVAL_TO_TIMESPEC(tv, ts) { \ |
| |
(ts)->tv_sec = (tv)->tv_sec; \ |
| |
(ts)->tv_nsec = (tv)->tv_usec * 1000; \ |
| |
} |
| |
#endif |
| |
|
| |
#ifndef TIMESPEC_TO_TIMEVAL |
| |
#define TIMESPEC_TO_TIMEVAL(tv, ts) { \ |
| |
(tv)->tv_sec = (ts)->tv_sec; \ |
| |
(tv)->tv_usec = (ts)->tv_nsec / 1000; \ |
| |
} |
| |
#endif |
| |
|
| |
/* Operations on timevals. */ |
| |
#ifndef timerclear |
| |
#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 |
| |
#endif |
| |
|
| |
#ifndef timerisset |
| |
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) |
| |
#endif |
| |
|
| |
#ifndef timercmp |
| |
#define timercmp(tvp, uvp, cmp) \ |
| |
(((tvp)->tv_sec == (uvp)->tv_sec) ? \ |
| |
((tvp)->tv_usec cmp (uvp)->tv_usec) : \ |
| |
((tvp)->tv_sec cmp (uvp)->tv_sec)) |
| |
#endif |
| |
|
| |
#ifndef timeradd |
| |
#define timeradd(tvp, uvp, vvp) \ |
| |
do { \ |
| |
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ |
| |
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ |
| |
if ((vvp)->tv_usec >= 1000000) { \ |
| |
(vvp)->tv_sec++; \ |
| |
(vvp)->tv_usec -= 1000000; \ |
| |
} \ |
| |
} while (0) |
| |
#endif |
| |
|
| |
#ifndef timersub |
| |
#define timersub(tvp, uvp, vvp) \ |
| |
do { \ |
| |
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ |
| |
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ |
| |
if ((vvp)->tv_usec < 0) { \ |
| |
(vvp)->tv_sec--; \ |
| |
(vvp)->tv_usec += 1000000; \ |
| |
} \ |
| |
} while (0) |
| |
#endif |
| |
|
| |
/* Operations on timespecs. */ |
| |
#ifndef timespecclear |
| |
#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 |
| |
#endif |
| |
|
| |
#ifndef timespecisset |
| |
#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) |
| |
#endif |
| |
|
| |
#ifndef timespeccmp |
| |
#define timespeccmp(tsp, usp, cmp) \ |
| |
(((tsp)->tv_sec == (usp)->tv_sec) ? \ |
| |
((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ |
| |
((tsp)->tv_sec cmp (usp)->tv_sec)) |
| |
#endif |
| |
|
| |
#ifndef timespecadd |
| |
#define timespecadd(tsp, usp, vsp) \ |
| |
do { \ |
| |
(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ |
| |
(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ |
| |
if ((vsp)->tv_nsec >= 1000000000L) { \ |
| |
(vsp)->tv_sec++; \ |
| |
(vsp)->tv_nsec -= 1000000000L; \ |
| |
} \ |
| |
} while (0) |
| |
#endif |
| |
|
| |
#ifndef timespecsub |
| |
#define timespecsub(tsp, usp, vsp) \ |
| |
do { \ |
| |
(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ |
| |
(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ |
| |
if ((vsp)->tv_nsec < 0) { \ |
| |
(vsp)->tv_sec--; \ |
| |
(vsp)->tv_nsec += 1000000000L; \ |
| |
} \ |
| |
} while (0) |
| |
#endif |
| |
|
| /* Macros for min/max. */ |
/* Macros for min/max. */ |
| #ifndef MIN |
#ifndef MIN |
| #define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
|
Line 177 SUCH DAMAGE.
|
Line 284 SUCH DAMAGE.
|
| #define VACUUM_BETWEEN 2 |
#define VACUUM_BETWEEN 2 |
| |
|
| |
|
| extern int __isthreaded; | typedef struct { |
| | E_ATOMIC_ALIGN int value; |
| | } e_atomic_int; |
| |
|
| |
#ifdef __cplusplus |
| |
extern "C" { |
| |
#endif |
| |
|
| |
extern int __isthreaded; |
| |
|
| // elwix_SetProg() Set program memory pool name |
// elwix_SetProg() Set program memory pool name |
| void elwix_SetProg(const char *csProgName); |
void elwix_SetProg(const char *csProgName); |
| // elwix_GetProg() Get program memory pool name |
// elwix_GetProg() Get program memory pool name |
|
Line 248 extern void (*e_free)(void*);
|
Line 362 extern void (*e_free)(void*);
|
| |
|
| /* Verbose macros */ |
/* Verbose macros */ |
| extern int elwix_Verbose; |
extern int elwix_Verbose; |
| |
#define e_Verbose elwix_Verbose |
| #define e_initVerbose(x) (elwix_Verbose = (x)) |
#define e_initVerbose(x) (elwix_Verbose = (x)) |
| #define e_incVerbose (elwix_Verbose++) |
#define e_incVerbose (elwix_Verbose++) |
| #define e_decVerbose (elwix_Verbose--) |
#define e_decVerbose (elwix_Verbose--) |
|
Line 255 extern int elwix_Verbose;
|
Line 370 extern int elwix_Verbose;
|
| #define EVERBS(x) if ((x) <= elwix_Verbose) |
#define EVERBS(x) if ((x) <= elwix_Verbose) |
| #define EVERBOSE(x, fmt, ...) do { assert((fmt)); \ |
#define EVERBOSE(x, fmt, ...) do { assert((fmt)); \ |
| if ((x) <= elwix_Verbose) { \ |
if ((x) <= elwix_Verbose) { \ |
| char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ | char __str[BUFSIZ] = { 0 }; \ |
| snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
| syslog(LOG_INFO, "Verbose(%d):%s(%d): %s\n", \ |
syslog(LOG_INFO, "Verbose(%d):%s(%d): %s\n", \ |
| (x), __func__, __LINE__, __str); \ |
(x), __func__, __LINE__, __str); \ |
|
Line 263 extern int elwix_Verbose;
|
Line 378 extern int elwix_Verbose;
|
| } while (0) |
} while (0) |
| #define EVERBOSE2(x, fmt, ...) do { assert((fmt)); \ |
#define EVERBOSE2(x, fmt, ...) do { assert((fmt)); \ |
| if ((x) <= elwix_Verbose) { \ |
if ((x) <= elwix_Verbose) { \ |
| char __str[0x10000] = { [0 ... 0xffff] = 0 }; \ | char __str[0x10000] = { 0 }; \ |
| snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
| syslog(LOG_INFO, "Verbose(%d):%s(%d): %s\n", \ |
syslog(LOG_INFO, "Verbose(%d):%s(%d): %s\n", \ |
| (x), __func__, __LINE__, __str); \ |
(x), __func__, __LINE__, __str); \ |
| } \ |
} \ |
| } while (0) |
} while (0) |
| |
|
| |
|
| /* Debug macros */ |
/* Debug macros */ |
| extern int elwix_Debug; |
extern int elwix_Debug; |
| #define e_Debug elwix_Debug |
#define e_Debug elwix_Debug |
|
Line 278 extern int elwix_Debug;
|
Line 392 extern int elwix_Debug;
|
| #define ELWIX_DEBUG_OFF 0x0 |
#define ELWIX_DEBUG_OFF 0x0 |
| #define ELWIX_DEBUG_TRACE 0x1 |
#define ELWIX_DEBUG_TRACE 0x1 |
| #define ELWIX_DEBUG_LOG 0x2 |
#define ELWIX_DEBUG_LOG 0x2 |
| |
#define ELWIX_DEBUG_MEM 0x4 |
| |
#define ELWIX_DEBUG_MEMORY ELWIX_DEBUG_MEM |
| |
#define ELWIX_DEBUG_IO 0x8 |
| |
#define ELWIX_DEBUG_IPC 0x10 |
| |
#define ELWIX_DEBUG_LOCK 0x20 |
| |
#define ELWIX_DEBUG_SYS 0x40 |
| |
#define ELWIX_DEBUG_NET 0x80 |
| |
#define ELWIX_DEBUG_1 0x100 |
| |
#define ELWIX_DEBUG_2 0x200 |
| |
#define ELWIX_DEBUG_3 0x400 |
| |
#define ELWIX_DEBUG_4 0x800 |
| #define ELWIX_DEBUG_ANY 0xFFFFFFFF |
#define ELWIX_DEBUG_ANY 0xFFFFFFFF |
| |
|
| |
#define EDBG(x) (elwix_Debug & (x)) |
| |
#define EDBGS(x) if (EDBG(x)) |
| #define ETRACE() if (elwix_Debug & ELWIX_DEBUG_TRACE) \ |
#define ETRACE() if (elwix_Debug & ELWIX_DEBUG_TRACE) \ |
| syslog(LOG_DEBUG, "I'm in %s(%d)\n", __func__, __LINE__) |
syslog(LOG_DEBUG, "I'm in %s(%d)\n", __func__, __LINE__) |
| #define EDEBUG(x, fmt, ...) do { assert((fmt)); \ |
#define EDEBUG(x, fmt, ...) do { assert((fmt)); \ |
| if ((x) & elwix_Debug) { \ |
if ((x) & elwix_Debug) { \ |
| char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ | char __str[BUFSIZ] = { 0 }; \ |
| snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
| syslog(LOG_DEBUG, "Debug(%d):%s(%d): %s\n", \ |
syslog(LOG_DEBUG, "Debug(%d):%s(%d): %s\n", \ |
| (x), __func__, __LINE__, __str); \ |
(x), __func__, __LINE__, __str); \ |
|
Line 293 extern int elwix_Debug;
|
Line 420 extern int elwix_Debug;
|
| |
|
| /* Logger macro */ |
/* Logger macro */ |
| #define ELOGGER(x, fmt, ...) do { assert((fmt)); \ |
#define ELOGGER(x, fmt, ...) do { assert((fmt)); \ |
| char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ | char __str[BUFSIZ] = { 0 }; \ |
| snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
| syslog((x), "Logger:%s(%d): %s\n", \ | syslog((x), "Log:%s(%d): %s\n", \ |
| __func__, __LINE__, __str); \ |
__func__, __LINE__, __str); \ |
| } while (0) |
} while (0) |
| |
|
| #define EWARNING(x, fmt, ...) do { assert((fmt)); \ |
#define EWARNING(x, fmt, ...) do { assert((fmt)); \ |
| char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ | char __str[BUFSIZ] = { 0 }; \ |
| snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
| syslog(LOG_WARNING, "Warning:%s(%d): #%d - %s\n", \ |
syslog(LOG_WARNING, "Warning:%s(%d): #%d - %s\n", \ |
| __func__, __LINE__, (x), __str); \ |
__func__, __LINE__, (x), __str); \ |
| } while (0) |
} while (0) |
| /* Error state macros */ |
/* Error state macros */ |
| #define EERROR(x, fmt, ...) do { assert((fmt)); \ |
#define EERROR(x, fmt, ...) do { assert((fmt)); \ |
| char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ | char __str[BUFSIZ] = { 0 }; \ |
| snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ |
| syslog(LOG_ERR, "Error:%s(%d): #%d - %s\n", \ |
syslog(LOG_ERR, "Error:%s(%d): #%d - %s\n", \ |
| __func__, __LINE__, (x), __str); \ |
__func__, __LINE__, (x), __str); \ |
|
Line 328 extern int elwix_Debug;
|
Line 455 extern int elwix_Debug;
|
| ait##_GetError()); \ |
ait##_GetError()); \ |
| } while (0) |
} while (0) |
| |
|
| |
|
| |
#ifdef __cplusplus |
| |
} |
| |
#endif |
| |
|
| #endif |
#endif |