diff options
Diffstat (limited to 'src/include/platform_interface.h')
-rw-r--r-- | src/include/platform_interface.h | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/include/platform_interface.h b/src/include/platform_interface.h new file mode 100644 index 00000000..22f78166 --- /dev/null +++ b/src/include/platform_interface.h | |||
@@ -0,0 +1,142 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2014 Karlson2k (Evgeny Grin) | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library. | ||
17 | If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file platform/platfrom_interface.h | ||
22 | * @brief internal platform abstraction functions | ||
23 | * @author Karlson2k (Evgeny Grin) | ||
24 | */ | ||
25 | |||
26 | #ifndef MHD_PLATFORM_INTERFACE_H | ||
27 | #define MHD_PLATFORM_INTERFACE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #if defined(_WIN32) && !defined(__CYGWIN__) | ||
31 | #include "w32functions.h" | ||
32 | #endif | ||
33 | |||
34 | /* MHD_socket_close_(fd) close any FDs (non-W32) / close only socket FDs (W32) */ | ||
35 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
36 | #define MHD_socket_close_(fd) close((fd)) | ||
37 | #else | ||
38 | #define MHD_socket_close_(fd) closesocket((fd)) | ||
39 | #endif | ||
40 | |||
41 | /* MHD_socket_errno_ is errno of last function (non-W32) / errno of last socket function (W32) */ | ||
42 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
43 | #define MHD_socket_errno_ errno | ||
44 | #else | ||
45 | #define MHD_socket_errno_ MHD_W32_errno_from_winsock_() | ||
46 | #endif | ||
47 | |||
48 | /* MHD_socket_last_strerr_ is description string of last errno (non-W32) / | ||
49 | * description string of last socket error (W32) */ | ||
50 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
51 | #define MHD_socket_last_strerr_() strerror(errno) | ||
52 | #else | ||
53 | #define MHD_socket_last_strerr_() MHD_W32_strerror_last_winsock_() | ||
54 | #endif | ||
55 | |||
56 | /* MHD_strerror_ is strerror (both non-W32/W32) */ | ||
57 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
58 | #define MHD_strerror_(errnum) strerror((errnum)) | ||
59 | #else | ||
60 | #define MHD_strerror_(errnum) MHD_W32_strerror_((errnum)) | ||
61 | #endif | ||
62 | |||
63 | /* MHD_set_socket_errno_ set errno to errnum (non-W32) / set socket last error to errnum (W32) */ | ||
64 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
65 | #define MHD_set_socket_errno_(errnum) errno=(errnum) | ||
66 | #else | ||
67 | #define MHD_set_socket_errno_(errnum) MHD_W32_set_last_winsock_error_((errnum)) | ||
68 | #endif | ||
69 | |||
70 | /* MHD_SYS_select_ is wrapper macro for system select() function */ | ||
71 | #if !defined(MHD_WINSOCK_SOCKETS) | ||
72 | #define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t)) | ||
73 | #else | ||
74 | #define MHD_SYS_select_(n,r,w,e,t) select((int)0,(r),(w),(e),(t)) | ||
75 | #endif | ||
76 | |||
77 | /* MHD_pipe_ create pipe (!MHD_DONT_USE_PIPES) / | ||
78 | * create two connected sockets (MHD_DONT_USE_PIPES) */ | ||
79 | #ifndef MHD_DONT_USE_PIPES | ||
80 | #define MHD_pipe_(fdarr) pipe((fdarr)) | ||
81 | #else /* MHD_DONT_USE_PIPES */ | ||
82 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
83 | #define MHD_pipe_(fdarr) socketpair(AF_LOCAL, SOCK_STREAM, 0, (fdarr)) | ||
84 | #else /* !defined(_WIN32) || defined(__CYGWIN__) */ | ||
85 | #define MHD_pipe_(fdarr) MHD_W32_pair_of_sockets_((fdarr)) | ||
86 | #endif /* !defined(_WIN32) || defined(__CYGWIN__) */ | ||
87 | #endif /* MHD_DONT_USE_PIPES */ | ||
88 | |||
89 | /* MHD_pipe_errno_ is errno of last function (!MHD_DONT_USE_PIPES) / | ||
90 | * errno of last emulated pipe function (MHD_DONT_USE_PIPES) */ | ||
91 | #ifndef MHD_DONT_USE_PIPES | ||
92 | #define MHD_pipe_errno_ errno | ||
93 | #else | ||
94 | #define MHD_pipe_errno_ MHD_socket_errno_ | ||
95 | #endif | ||
96 | |||
97 | /* MHD_pipe_last_strerror_ is description string of last errno (!MHD_DONT_USE_PIPES) / | ||
98 | * description string of last pipe error (MHD_DONT_USE_PIPES) */ | ||
99 | #ifndef MHD_DONT_USE_PIPES | ||
100 | #define MHD_pipe_last_strerror_() strerror(errno) | ||
101 | #else | ||
102 | #define MHD_pipe_last_strerror_() MHD_socket_last_strerr_() | ||
103 | #endif | ||
104 | |||
105 | /* MHD_pipe_write_ write data to real pipe (!MHD_DONT_USE_PIPES) / | ||
106 | * write data to emulated pipe (MHD_DONT_USE_PIPES) */ | ||
107 | #ifndef MHD_DONT_USE_PIPES | ||
108 | #define MHD_pipe_write_(fd, ptr, sz) write((fd), (const void*)(ptr), (sz)) | ||
109 | #else | ||
110 | #define MHD_pipe_write_(fd, ptr, sz) send((fd), (const char*)(ptr), (sz), 0) | ||
111 | #endif | ||
112 | |||
113 | /* MHD_pipe_read_ read data from real pipe (!MHD_DONT_USE_PIPES) / | ||
114 | * read data from emulated pipe (MHD_DONT_USE_PIPES) */ | ||
115 | #ifndef MHD_DONT_USE_PIPES | ||
116 | #define MHD_pipe_read_(fd, ptr, sz) read((fd), (void*)(ptr), (sz)) | ||
117 | #else | ||
118 | #define MHD_pipe_read_(fd, ptr, sz) recv((fd), (char*)(ptr), (sz), 0) | ||
119 | #endif | ||
120 | |||
121 | /* MHD_pipe_close_(fd) close any FDs (non-W32) / | ||
122 | * close emulated pipe FDs (W32) */ | ||
123 | #ifndef MHD_DONT_USE_PIPES | ||
124 | #define MHD_pipe_close_(fd) close((fd)) | ||
125 | #else | ||
126 | #define MHD_pipe_close_(fd) MHD_socket_close_((fd)) | ||
127 | #endif | ||
128 | |||
129 | /* MHD_INVALID_PIPE_ is a value of bad pipe FD */ | ||
130 | #ifndef MHD_DONT_USE_PIPES | ||
131 | #define MHD_INVALID_PIPE_ (-1) | ||
132 | #else | ||
133 | #define MHD_INVALID_PIPE_ MHD_INVALID_SOCKET | ||
134 | #endif | ||
135 | |||
136 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
137 | #define MHD_random_() random() | ||
138 | #else | ||
139 | #define MHD_random_() MHD_W32_random() | ||
140 | #endif | ||
141 | |||
142 | #endif // MHD_PLATFORM_INTERFACE_H | ||