-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
58 lines (46 loc) · 1.92 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
#ifndef COMMON_H
#define COMMON_H
#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <ev.h>
#include "params.h"
#include "stats.h"
#define DEBUG 1
#define debug_print(fmt, ...) \
do{ if (DEBUG) { \
fprintf(stderr, "%s:%d:%s: " fmt, \
__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
}} while (0)
#define debug_pprint(fmt, ...) \
do { if (DEBUG) { \
fprintf(stderr, "%s:%d:%s: " fmt, \
__FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__);\
}} while (0)
#define debug_socket_print(sd, fmt, ...) \
do { if (DEBUG) { \
struct sockaddr_in sa_from, sa_to; \
socklen_t saf_len = sizeof(sa_from); \
socklen_t sat_len = sizeof(sa_to); \
getsockname(sd, (sockaddr*)&sa_from, &saf_len); \
getpeername(sd, (sockaddr*)&sa_to, &sat_len); \
fprintf(stderr, "%s:%d:%s:[%s:%d->%s:%d]: " fmt, \
__FILE__, __LINE__, __FUNCTION__, \
inet_ntoa(sa_from.sin_addr), ntohs(sa_from.sin_port), \
inet_ntoa(sa_to.sin_addr), ntohs(sa_to.sin_port), \
##__VA_ARGS__); \
}} while (0)
#endif