26 #ifndef MHD_PLATFORM_INTERFACE_H 27 #define MHD_PLATFORM_INTERFACE_H 30 #if defined(_WIN32) && !defined(__CYGWIN__) 37 #if !defined(_WIN32) || defined(__CYGWIN__) 44 #define MHD_str_equal_caseless_(a,b) (0==strcasecmp((a),(b))) 52 #define MHD_str_equal_caseless_(a,b) (0==_stricmp((a),(b))) 55 #if !defined(_WIN32) || defined(__CYGWIN__) 63 #define MHD_str_equal_caseless_n_(a,b,n) (0==strncasecmp((a),(b),(n))) 72 #define MHD_str_equal_caseless_n_(a,b,n) (0==_strnicmp((a),(b),(n))) 76 #if !defined(_WIN32) || defined(__CYGWIN__) 77 #define MHD_snprintf_ snprintf 79 #define MHD_snprintf_ W32_snprintf 87 #if !defined(MHD_WINSOCK_SOCKETS) 102 #if !defined(MHD_WINSOCK_SOCKETS) 103 #define MHD_socket_close_(fd) (((0 != close(fd)) && (EBADF == errno)) ? -1 : 0) 105 #define MHD_socket_close_(fd) closesocket((fd)) 112 #if !defined(MHD_WINSOCK_SOCKETS) 113 #define MHD_socket_errno_ errno 115 #define MHD_socket_errno_ MHD_W32_errno_from_winsock_() 120 #if !defined(MHD_WINSOCK_SOCKETS) 121 #define MHD_socket_last_strerr_() strerror(errno) 123 #define MHD_socket_last_strerr_() MHD_W32_strerror_last_winsock_() 127 #if !defined(MHD_WINSOCK_SOCKETS) 128 #define MHD_strerror_(errnum) strerror((errnum)) 130 #define MHD_strerror_(errnum) MHD_W32_strerror_((errnum)) 134 #if !defined(MHD_WINSOCK_SOCKETS) 135 #define MHD_set_socket_errno_(errnum) errno=(errnum) 137 #define MHD_set_socket_errno_(errnum) MHD_W32_set_last_winsock_error_((errnum)) 141 #if !defined(MHD_WINSOCK_SOCKETS) 142 #define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t)) 144 #define MHD_SYS_select_(n,r,w,e,t) select((int)0,(r),(w),(e),(t)) 147 #if defined(HAVE_POLL) 149 #if !defined(MHD_WINSOCK_SOCKETS) 150 #define MHD_sys_poll_ poll 152 #define MHD_sys_poll_ WSAPoll 158 #ifndef MHD_DONT_USE_PIPES 159 #define MHD_pipe_(fdarr) pipe((fdarr)) 161 #if !defined(_WIN32) || defined(__CYGWIN__) 162 #define MHD_pipe_(fdarr) socketpair(AF_LOCAL, SOCK_STREAM, 0, (fdarr)) 164 #define MHD_pipe_(fdarr) MHD_W32_pair_of_sockets_((fdarr)) 170 #ifndef MHD_DONT_USE_PIPES 171 #define MHD_pipe_errno_ errno 173 #define MHD_pipe_errno_ MHD_socket_errno_ 178 #ifndef MHD_DONT_USE_PIPES 179 #define MHD_pipe_last_strerror_() strerror(errno) 181 #define MHD_pipe_last_strerror_() MHD_socket_last_strerr_() 186 #ifndef MHD_DONT_USE_PIPES 187 #define MHD_pipe_write_(fd, ptr, sz) write((fd), (const void*)(ptr), (sz)) 189 #define MHD_pipe_write_(fd, ptr, sz) send((fd), (const char*)(ptr), (sz), 0) 194 #ifndef MHD_DONT_USE_PIPES 195 #define MHD_pipe_read_(fd, ptr, sz) read((fd), (void*)(ptr), (sz)) 197 #define MHD_pipe_read_(fd, ptr, sz) recv((fd), (char*)(ptr), (sz), 0) 202 #ifndef MHD_DONT_USE_PIPES 203 #define MHD_pipe_close_(fd) close((fd)) 205 #define MHD_pipe_close_(fd) MHD_socket_close_((fd)) 209 #ifndef MHD_DONT_USE_PIPES 210 #define MHD_INVALID_PIPE_ (-1) 212 #define MHD_INVALID_PIPE_ MHD_INVALID_SOCKET 215 #if !defined(_WIN32) || defined(__CYGWIN__) 216 #define MHD_random_() random() 218 #define MHD_random_() MHD_W32_random_() 221 #if defined(MHD_USE_POSIX_THREADS) 222 typedef pthread_t MHD_thread_handle_;
223 #elif defined(MHD_USE_W32_THREADS) 225 typedef HANDLE MHD_thread_handle_;
227 #error "No threading API is available." 230 #if defined(MHD_USE_POSIX_THREADS) 231 #define MHD_THRD_RTRN_TYPE_ void* 232 #define MHD_THRD_CALL_SPEC_ 233 #elif defined(MHD_USE_W32_THREADS) 234 #define MHD_THRD_RTRN_TYPE_ unsigned 235 #define MHD_THRD_CALL_SPEC_ __stdcall 238 #if defined(MHD_USE_POSIX_THREADS) 244 #define MHD_join_thread_(thread) pthread_join((thread), NULL) 245 #elif defined(MHD_USE_W32_THREADS) 252 #define MHD_join_thread_(thread) (WAIT_OBJECT_0 == WaitForSingleObject((thread), INFINITE) ? (CloseHandle((thread)), 0) : 1 ) 255 #if defined(MHD_USE_W32_THREADS) 256 #define MHD_W32_MUTEX_ 1 258 typedef CRITICAL_SECTION MHD_mutex_;
259 #elif defined(HAVE_PTHREAD_H) && defined(MHD_USE_POSIX_THREADS) 260 #define MHD_PTHREAD_MUTEX_ 1 261 typedef pthread_mutex_t MHD_mutex_;
263 #error "No base mutex API is available." 266 #if defined(MHD_PTHREAD_MUTEX_) 272 #define MHD_mutex_create_(mutex) \ 273 ((0 == pthread_mutex_init ((mutex), NULL)) ? MHD_YES : MHD_NO) 274 #elif defined(MHD_W32_MUTEX_) 280 #define MHD_mutex_create_(mutex) \ 281 ((NULL != (mutex) && 0 != InitializeCriticalSectionAndSpinCount((mutex),2000)) ? MHD_YES : MHD_NO) 284 #if defined(MHD_PTHREAD_MUTEX_) 290 #define MHD_mutex_destroy_(mutex) \ 291 ((0 == pthread_mutex_destroy ((mutex))) ? MHD_YES : MHD_NO) 292 #elif defined(MHD_W32_MUTEX_) 298 #define MHD_mutex_destroy_(mutex) \ 299 ((NULL != (mutex)) ? (DeleteCriticalSection(mutex), MHD_YES) : MHD_NO) 302 #if defined(MHD_PTHREAD_MUTEX_) 310 #define MHD_mutex_lock_(mutex) \ 311 ((0 == pthread_mutex_lock((mutex))) ? MHD_YES : MHD_NO) 312 #elif defined(MHD_W32_MUTEX_) 320 #define MHD_mutex_lock_(mutex) \ 321 ((NULL != (mutex)) ? (EnterCriticalSection((mutex)), MHD_YES) : MHD_NO) 324 #if defined(MHD_PTHREAD_MUTEX_) 332 #define MHD_mutex_trylock_(mutex) \ 333 ((0 == pthread_mutex_trylock((mutex))) ? MHD_YES : MHD_NO) 334 #elif defined(MHD_W32_MUTEX_) 342 #define MHD_mutex_trylock_(mutex) \ 343 ((NULL != (mutex) && 0 != TryEnterCriticalSection ((mutex))) ? MHD_YES : MHD_NO) 346 #if defined(MHD_PTHREAD_MUTEX_) 352 #define MHD_mutex_unlock_(mutex) \ 353 ((0 == pthread_mutex_unlock((mutex))) ? MHD_YES : MHD_NO) 354 #elif defined(MHD_W32_MUTEX_) 360 #define MHD_mutex_unlock_(mutex) \ 361 ((NULL != (mutex)) ? (LeaveCriticalSection((mutex)), MHD_YES) : MHD_NO) internal functions for W32 systems