forked from cfadmin-cn/cfadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_sys.h
More file actions
55 lines (44 loc) · 1.25 KB
/
core_sys.h
File metadata and controls
55 lines (44 loc) · 1.25 KB
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
#ifndef __CORE_SYS__
#define __CORE_SYS__
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <math.h>
#include <limits.h>
#include <time.h>
#include <errno.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <fcntl.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#ifndef EWOULDBLOCK
#define EWOULDBLOCK EAGAIN
#endif
#define non_blocking(socket) (fcntl(socket, F_SETFL, fcntl(socket, F_GETFL, 0) | O_NONBLOCK));
/* [datetime][level][file][function][line][具体打印内容] */
#define LOG(log_level, content) { \
time_t t; struct tm* lt; \
/*获取Unix时间戳、转为时间结构。*/ \
time(&t); lt = localtime(&t); \
fprintf(stdout, "[%04d/%02d/%02d][%02d:%02d:%02d][%s][%s][%s:%d] : %s\n", \
lt->tm_year+1900, 1+lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, \
log_level, \
__FILE__, __FUNCTION__, __LINE__, \
content);}
/* 微秒级double时间戳 */
double now();
/* 检查是否为有效ipv4地址 */
int ipv4(const char *IP);
/* 检查是否为有效ipv6地址 */
int ipv6(const char *IP);
#endif