Repository navigation
Expand file tree
/
Copy pathmeinheld.h
More file actions
134 lines (119 loc) · 3.33 KB
/
Copy pathmeinheld.h
File metadata and controls
134 lines (119 loc) · 3.33 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef MEINHELD_H
#define MEINHELD_H
#include <Python.h>
#include <structmember.h>
#include <assert.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
#ifdef linux
#include <sys/sendfile.h>
#elif defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/uio.h>
#endif
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <time.h>
#include <sys/time.h>
#include "http_parser.h"
#define SERVER "meinheld/0.5.5"
#define MODULE_NAME "meinheld.server"
#ifdef DEVELOP
#define DEBUG(...) \
do { \
/*printf("DEBUG: ");*/ \
printf("%-40s %-26s%4u: ", __FILE__, __func__, __LINE__); \
printf(__VA_ARGS__); \
printf("\n"); \
} while(0)
#define RDEBUG(...) \
do { \
/*printf("%-22s%4u: ", __FILE__, __LINE__);*/ \
printf("\x1B[31m%-40s %-26s%4u: ", __FILE__, __func__, __LINE__); \
printf(__VA_ARGS__); \
printf("\x1B[0m\n"); \
} while(0)
#define GDEBUG(...) \
do { \
/*printf("%-22s%4u: ", __FILE__, __LINE__);*/ \
printf("\x1B[32m%-40s %-26s%4u: ", __FILE__, __func__, __LINE__); \
printf(__VA_ARGS__); \
printf("\x1B[0m\n"); \
} while(0)
#define BDEBUG(...) \
do { \
/*printf("%-22s%4u: ", __FILE__, __LINE__);*/ \
printf("\x1B[1;34m%-40s %-26s%4u: ", __FILE__, __func__, __LINE__); \
printf(__VA_ARGS__); \
printf("\x1B[0m\n"); \
} while(0)
#define YDEBUG(...) \
do { \
/*printf("%-22s%4u: ", __FILE__, __LINE__);*/ \
printf("\x1B[1;33m%-40s %-26s%4u: ", __FILE__, __func__, __LINE__); \
printf(__VA_ARGS__); \
printf("\x1B[0m\n"); \
} while(0)
#else
#define DEBUG(...) do{}while(0)
#define RDEBUG(...) do{}while(0)
#define GDEBUG(...) do{}while(0)
#define BDEBUG(...) do{}while(0)
#define YDEBUG(...) do{}while(0)
#endif
#if __GNUC__ >= 3
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
#else
# define likely(x) (x)
# define unlikely(x) (x)
#endif
#define NO_GREENLET_ERROR \
PyErr_SetString(PyExc_NotImplementedError, "greenlet not support"); \
return NULL;\
//#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || PY_MAJOR_VERSION > 3
#if PY_MAJOR_VERSION >= 3
static __inline__ char*
as_str(PyObject* obj)
{
char *c = NULL;
PyObject *latin1;
latin1 = PyUnicode_AsLatin1String(obj);
if(latin1 == NULL){
return NULL;
}
c = PyBytes_AsString(latin1);
Py_DECREF(latin1);
return c;
}
# define PY3
# define NATIVE_GET_STRING_SIZE PyUnicode_GET_SIZE
# define NATIVE_ASSTRING as_str
# define NATIVE_FROMSTRING PyUnicode_FromString
# define NATIVE_FROMSTRINGANDSIZE PyUnicode_FromStringAndSize
# define NATIVE_FROMFORMAT PyUnicode_FromFormat
#else
# define NATIVE_GET_STRING_SIZE PyBytes_GET_SIZE
# define NATIVE_ASSTRING PyBytes_AsString
# define NATIVE_FROMSTRING PyBytes_FromString
# define NATIVE_FROMSTRINGANDSIZE PyBytes_FromStringAndSize
# define NATIVE_FROMFORMAT PyBytes_FromFormat
#endif
#if PY_MAJOR_VERSION < 3
#ifndef Py_REFCNT
# define Py_REFCNT(ob) (((PyObject *) (ob))->ob_refcnt)
#endif
#ifndef Py_TYPE
# define Py_TYPE(ob) (((PyObject *) (ob))->ob_type)
#endif
#endif
#endif