-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommon.h
executable file
·76 lines (69 loc) · 1.67 KB
/
common.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
/**
*@brief:主要的库头文件及一些声明
*/
#ifndef _COMMON_H
#define _COMMON_H
#include <iostream>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <netdb.h>
#include <sys/socket.h>//套接字编程
#include <netinet/in.h>//地址
#include <fcntl.h>
#include <arpa/inet.h>
#include <string.h>
#include <string>
#include <map>
#include <pwd.h>
#include <shadow.h>
#include <crypt.h>
#include <ctype.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/syscall.h>
#include <signal.h>
#include <sys/sendfile.h>
#include <sys/timerfd.h>
#include <pthread.h>
#include <sys/epoll.h>
//'\'后面不要加注释
/**
*FTPD_LOG - 日志宏
*输出日期,时间,日志级别,源码文件,行号,信息
*/
//定义一个日志宏
#define DEBUG 0
#define INFO 1
#define WARN 2
#define ERROR 3
#define CRIT 4
static const char* LOG_STR[] = {
"DEBUG",
"INFO",
"WARN",
"ERROR",
"CRIT"
};
#define CHEN_LOG(level, format, ...) do{ \
char msg[1024]; \
char buf[32]; \
sprintf(msg, format, ##__VA_ARGS__); \
if (level >= 0) {\
time_t now = time(NULL); \
strftime(buf, sizeof(buf), "%H:%M:%S", localtime(&now)); \
fprintf(stdout, "[%s] [%s] [file:%s] [line:%d] [tid:%ld] %s\n",buf, \
LOG_STR[level],__FILE__,__LINE__,pthread_self(), msg); \
fflush (stdout); \
}\
if (level >= ERROR) {\
perror(msg); \
exit(-1); \
} \
} while(0)
#endif