/
ixp_local.h
99 lines (79 loc) · 2.14 KB
/
ixp_local.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#define IXP_NO_P9_
#include <ixp.h>
#include <stdbool.h>
#undef ulong
#define ulong _ixpulong
typedef unsigned long ulong;
#ifdef CPROTO
# undef bool
typedef int bool;
typedef char* va_list;
#endif
#define ARGBEGIN \
int _argtmp=0, _inargv=0; char *_argv=nil; \
if(!argv0) {argv0=*argv; argv++, argc--;} \
_inargv=1; USED(_inargv); \
while(argc && argv[0][0] == '-') { \
_argv=&argv[0][1]; argv++; argc--; \
if(_argv[0] == '-' && _argv[1] == '\0') \
break; \
while(*_argv) switch(*_argv++)
#define ARGEND }_inargv=0;USED(_argtmp, _argv, _inargv)
#define EARGF(f) ((_inargv && *_argv) ? \
(_argtmp=strlen(_argv), _argv+=_argtmp, _argv-_argtmp) \
: ((argc > 0) ? \
(--argc, ++argv, _used(argc), *(argv-1)) \
: ((f), (char*)0)))
#define ARGF() EARGF(_used(0))
#ifndef KENC
static inline void _used(long a, ...) { if(a){} }
# define USED(...) _used((long)__VA_ARGS__)
# define SET(x) (x = 0)
/* # define SET(x) USED(&x) GCC 4 is 'too smart' for this. */
#endif
#undef nil
#define nil ((void*)0)
#define nelem(ary) (sizeof(ary) / sizeof(*ary))
#define thread ixp_thread
#define eprint ixp_eprint
#define emalloc ixp_emalloc
#define emallocz ixp_emallocz
#define estrdup ixp_estrdup
#define erealloc ixp_erealloc
#define strlcat ixp_strlcat
#define tokenize ixp_tokenize
#define muxinit ixp_muxinit
#define muxfree ixp_muxfree
#define muxrpc ixp_muxrpc
#define errstr ixp_errstr
#define rerrstr ixp_rerrstr
#define werrstr ixp_werrstr
typedef struct IxpMap Map;
typedef struct MapEnt MapEnt;
typedef IxpTimer Timer;
typedef struct timeval timeval;
struct IxpMap {
MapEnt** bucket;
int nhash;
IxpRWLock lock;
};
struct IxpTimer {
Timer* link;
uint64_t msec;
long id;
void (*fn)(long, void*);
void* aux;
};
/* map.c */
void ixp_mapfree(IxpMap*, void(*)(void*));
void ixp_mapexec(IxpMap*, void(*)(void*, void*), void*);
void ixp_mapinit(IxpMap*, MapEnt**, int);
bool ixp_mapinsert(IxpMap*, ulong, void*, bool);
void* ixp_mapget(IxpMap*, ulong);
void* ixp_maprm(IxpMap*, ulong);
/* mux.c */
void muxfree(IxpClient*);
void muxinit(IxpClient*);
IxpFcall* muxrpc(IxpClient*, IxpFcall*);
/* timer.c */
long ixp_nexttimer(IxpServer*);