diff options
Diffstat (limited to 'src/microhttpd/mhd_sockets.h')
-rw-r--r-- | src/microhttpd/mhd_sockets.h | 434 |
1 files changed, 276 insertions, 158 deletions
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h index 3a3e4b85..b38a5d55 100644 --- a/src/microhttpd/mhd_sockets.h +++ b/src/microhttpd/mhd_sockets.h | |||
@@ -204,38 +204,6 @@ | |||
204 | # define MHD_socket_close_(fd) closesocket((fd)) | 204 | # define MHD_socket_close_(fd) closesocket((fd)) |
205 | #endif | 205 | #endif |
206 | 206 | ||
207 | /** | ||
208 | * MHD_socket_errno_ is errno of last function (non-W32) / errno of | ||
209 | * last socket function (W32) | ||
210 | */ | ||
211 | #if !defined(MHD_WINSOCK_SOCKETS) | ||
212 | # define MHD_socket_errno_ errno | ||
213 | #else | ||
214 | # define MHD_socket_errno_ MHD_W32_errno_from_winsock_() | ||
215 | #endif | ||
216 | |||
217 | /* MHD_socket_last_strerr_ is description string of last errno (non-W32) / | ||
218 | * description string of last socket error (W32) */ | ||
219 | #if !defined(MHD_WINSOCK_SOCKETS) | ||
220 | # define MHD_socket_last_strerr_() strerror(errno) | ||
221 | #else | ||
222 | # define MHD_socket_last_strerr_() MHD_W32_strerror_last_winsock_() | ||
223 | #endif | ||
224 | |||
225 | /* MHD_strerror_ is strerror (both non-W32/W32) */ | ||
226 | #if !defined(MHD_WINSOCK_SOCKETS) | ||
227 | # define MHD_strerror_(errnum) strerror((errnum)) | ||
228 | #else | ||
229 | # define MHD_strerror_(errnum) MHD_W32_strerror_((errnum)) | ||
230 | #endif | ||
231 | |||
232 | /* MHD_set_socket_errno_ set errno to errnum (non-W32) / set socket last error to errnum (W32) */ | ||
233 | #if !defined(MHD_WINSOCK_SOCKETS) | ||
234 | # define MHD_set_socket_errno_(errnum) errno=(errnum) | ||
235 | #else | ||
236 | # define MHD_set_socket_errno_(errnum) MHD_W32_set_last_winsock_error_((errnum)) | ||
237 | #endif | ||
238 | |||
239 | /* MHD_SYS_select_ is wrapper macro for system select() function */ | 207 | /* MHD_SYS_select_ is wrapper macro for system select() function */ |
240 | #if !defined(MHD_WINSOCK_SOCKETS) | 208 | #if !defined(MHD_WINSOCK_SOCKETS) |
241 | # define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t)) | 209 | # define MHD_SYS_select_(n,r,w,e,t) select((n),(r),(w),(e),(t)) |
@@ -257,150 +225,300 @@ | |||
257 | # endif /* MHD_WINSOCK_SOCKETS */ | 225 | # endif /* MHD_WINSOCK_SOCKETS */ |
258 | #endif /* HAVE_POLL */ | 226 | #endif /* HAVE_POLL */ |
259 | 227 | ||
228 | #define MHD_SCKT_MISSING_ERR_CODE_ 31450 | ||
229 | |||
230 | #if defined(MHD_POSIX_SOCKETS) | ||
231 | # if defined(EAGAIN) | ||
232 | # define MHD_SCKT_EAGAIN_ EAGAIN | ||
233 | # elif defined(EWOULDBLOCK) | ||
234 | # define MHD_SCKT_EAGAIN_ EWOULDBLOCK | ||
235 | # else /* !EAGAIN && !EWOULDBLOCK */ | ||
236 | # define MHD_SCKT_EAGAIN_ MHD_SCKT_MISSING_ERR_CODE_ | ||
237 | # endif /* !EAGAIN && !EWOULDBLOCK */ | ||
238 | # if defined(EWOULDBLOCK) | ||
239 | # define MHD_SCKT_EWOULDBLOCK_ EWOULDBLOCK | ||
240 | # elif defined(EAGAIN) | ||
241 | # define MHD_SCKT_EWOULDBLOCK_ EAGAIN | ||
242 | # else /* !EWOULDBLOCK && !EAGAIN */ | ||
243 | # define MHD_SCKT_EWOULDBLOCK_ MHD_SCKT_MISSING_ERR_CODE_ | ||
244 | # endif /* !EWOULDBLOCK && !EAGAIN */ | ||
245 | # ifdef EINTR | ||
246 | # define MHD_SCKT_EINTR_ EINTR | ||
247 | # else /* ! EINTR */ | ||
248 | # define MHD_SCKT_EINTR_ MHD_SCKT_MISSING_ERR_CODE_ | ||
249 | # endif /* ! EINTR */ | ||
250 | # ifdef ECONNRESET | ||
251 | # define MHD_SCKT_ECONNRESET_ ECONNRESET | ||
252 | # else /* ! ECONNRESET */ | ||
253 | # define MHD_SCKT_ECONNRESET_ MHD_SCKT_MISSING_ERR_CODE_ | ||
254 | # endif /* ! ECONNRESET */ | ||
255 | # ifdef ECONNABORTED | ||
256 | # define MHD_SCKT_ECONNABORTED_ ECONNABORTED | ||
257 | # else /* ! ECONNABORTED */ | ||
258 | # define MHD_SCKT_ECONNABORTED_ MHD_SCKT_MISSING_ERR_CODE_ | ||
259 | # endif /* ! ECONNABORTED */ | ||
260 | # ifdef ENOTCONN | ||
261 | # define MHD_SCKT_ENOTCONN_ ENOTCONN | ||
262 | # else /* ! ENOTCONN */ | ||
263 | # define MHD_SCKT_ENOTCONN_ MHD_SCKT_MISSING_ERR_CODE_ | ||
264 | # endif /* ! ENOTCONN */ | ||
265 | # ifdef EMFILE | ||
266 | # define MHD_SCKT_EMFILE_ EMFILE | ||
267 | # else /* ! EMFILE */ | ||
268 | # define MHD_SCKT_EMFILE_ MHD_SCKT_MISSING_ERR_CODE_ | ||
269 | # endif /* ! EMFILE */ | ||
270 | # ifdef ENFILE | ||
271 | # define MHD_SCKT_ENFILE_ ENFILE | ||
272 | # else /* ! ENFILE */ | ||
273 | # define MHD_SCKT_ENFILE_ MHD_SCKT_MISSING_ERR_CODE_ | ||
274 | # endif /* ! ENFILE */ | ||
275 | # ifdef ENOMEM | ||
276 | # define MHD_SCKT_ENOMEM_ ENOMEM | ||
277 | # else /* ! ENOMEM */ | ||
278 | # define MHD_SCKT_ENOMEM_ MHD_SCKT_MISSING_ERR_CODE_ | ||
279 | # endif /* ! ENOMEM */ | ||
280 | # ifdef ENOBUFS | ||
281 | # define MHD_SCKT_ENOBUFS_ ENOBUFS | ||
282 | # else /* ! ENOBUFS */ | ||
283 | # define MHD_SCKT_ENOBUFS_ MHD_SCKT_MISSING_ERR_CODE_ | ||
284 | # endif /* ! ENOBUFS */ | ||
285 | # ifdef EBADF | ||
286 | # define MHD_SCKT_EBADF_ EBADF | ||
287 | # else /* ! EBADF */ | ||
288 | # define MHD_SCKT_EBADF_ MHD_SCKT_MISSING_ERR_CODE_ | ||
289 | # endif /* ! EBADF */ | ||
290 | # ifdef ENOTSOCK | ||
291 | # define MHD_SCKT_ENOTSOCK_ ENOTSOCK | ||
292 | # else /* ! ENOTSOCK */ | ||
293 | # define MHD_SCKT_ENOTSOCK_ MHD_SCKT_MISSING_ERR_CODE_ | ||
294 | # endif /* ! ENOTSOCK */ | ||
295 | # ifdef EINVAL | ||
296 | # define MHD_SCKT_EINVAL_ EINVAL | ||
297 | # else /* ! EINVAL */ | ||
298 | # define MHD_SCKT_EINVAL_ MHD_SCKT_MISSING_ERR_CODE_ | ||
299 | # endif /* ! EINVAL */ | ||
300 | # ifdef EFAULT | ||
301 | # define MHD_SCKT_EFAUL_ EFAULT | ||
302 | # else /* ! EFAULT */ | ||
303 | # define MHD_SCKT_EFAUL_ MHD_SCKT_MISSING_ERR_CODE_ | ||
304 | # endif /* ! EFAULT */ | ||
305 | # ifdef ENOSYS | ||
306 | # define MHD_SCKT_ENOSYS_ ENOSYS | ||
307 | # else /* ! ENOSYS */ | ||
308 | # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_ | ||
309 | # endif /* ! ENOSYS */ | ||
310 | # ifdef ENOTSUP | ||
311 | # define MHD_SCKT_ENOTSUP_ ENOTSUP | ||
312 | # else /* ! ENOTSUP */ | ||
313 | # define MHD_SCKT_ENOTSUP_ MHD_SCKT_MISSING_ERR_CODE_ | ||
314 | # endif /* ! ENOTSUP */ | ||
315 | # ifdef EOPNOTSUPP | ||
316 | # define MHD_SCKT_EOPNOTSUPP_ EOPNOTSUPP | ||
317 | # else /* ! EOPNOTSUPP */ | ||
318 | # define MHD_SCKT_EOPNOTSUPP_ MHD_SCKT_MISSING_ERR_CODE_ | ||
319 | # endif /* ! EOPNOTSUPP */ | ||
320 | # ifdef EACCES | ||
321 | # define MHD_SCKT_EACCESS_ EACCES | ||
322 | # else /* ! EACCES */ | ||
323 | # define MHD_SCKT_EACCESS_ MHD_SCKT_MISSING_ERR_CODE_ | ||
324 | # endif /* ! EACCES */ | ||
325 | # ifdef ENETDOWN | ||
326 | # define MHD_SCKT_ENETDOWN_ ENETDOWN | ||
327 | # else /* ! ENETDOWN */ | ||
328 | # define MHD_SCKT_ENETDOWN_ MHD_SCKT_MISSING_ERR_CODE_ | ||
329 | # endif /* ! ENETDOWN */ | ||
330 | #elif defined(MHD_WINSOCK_SOCKETS) | ||
331 | # define MHD_SCKT_EAGAIN_ WSAEWOULDBLOCK | ||
332 | # define MHD_SCKT_EWOULDBLOCK_ WSAEWOULDBLOCK | ||
333 | # define MHD_SCKT_EINTR_ WSAEINTR | ||
334 | # define MHD_SCKT_ECONNRESET_ WSAECONNRESET | ||
335 | # define MHD_SCKT_ECONNABORTED_ WSAECONNABORTED | ||
336 | # define MHD_SCKT_ENOTCONN_ WSAENOTCONN | ||
337 | # define MHD_SCKT_EMFILE_ WSAEMFILE | ||
338 | # define MHD_SCKT_ENFILE_ MHD_SCKT_MISSING_ERR_CODE_ | ||
339 | # define MHD_SCKT_ENOMEM_ MHD_SCKT_MISSING_ERR_CODE_ | ||
340 | # define MHD_SCKT_ENOBUFS_ WSAENOBUFS | ||
341 | # define MHD_SCKT_EBADF_ WSAEBADF | ||
342 | # define MHD_SCKT_ENOTSOCK_ WSAENOTSOCK | ||
343 | # define MHD_SCKT_EINVAL_ WSAEINVAL | ||
344 | # define MHD_SCKT_EFAUL_ WSAEFAULT | ||
345 | # define MHD_SCKT_ENOSYS_ MHD_SCKT_MISSING_ERR_CODE_ | ||
346 | # define MHD_SCKT_ENOTSUP_ MHD_SCKT_MISSING_ERR_CODE_ | ||
347 | # define MHD_SCKT_EOPNOTSUPP_ WSAEOPNOTSUPP | ||
348 | # define MHD_SCKT_EACCESS_ WSAEACCES | ||
349 | # define MHD_SCKT_ENETDOWN_ WSAENETDOWN | ||
350 | #endif | ||
351 | |||
352 | /** | ||
353 | * MHD_socket_error_ return system native error code for last socket error. | ||
354 | * @return system error code for last socket error. | ||
355 | */ | ||
356 | #if defined(MHD_POSIX_SOCKETS) | ||
357 | # define MHD_socket_get_error_() (errno) | ||
358 | #elif defined(MHD_WINSOCK_SOCKETS) | ||
359 | # define MHD_socket_get_error_() WSAGetLastError() | ||
360 | #endif | ||
260 | 361 | ||
261 | #ifdef MHD_WINSOCK_SOCKETS | 362 | #ifdef MHD_WINSOCK_SOCKETS |
363 | /* POSIX-W32 sockets compatibility functions */ | ||
262 | 364 | ||
263 | /* POSIX-W32 compatibility functions and macros */ | 365 | /** |
366 | * Return pointer to string description of specified WinSock error | ||
367 | * @param err the WinSock error code. | ||
368 | * @return pointer to string description of specified WinSock error. | ||
369 | */ | ||
370 | const char* MHD_W32_strerror_winsock_(int err); | ||
371 | #endif /* MHD_WINSOCK_SOCKETS */ | ||
264 | 372 | ||
265 | # define MHDW32ERRBASE 3300 | 373 | /* MHD_socket_last_strerr_ is description string of specified socket error code */ |
374 | #if defined(MHD_POSIX_SOCKETS) | ||
375 | # define MHD_socket_strerr_(err) strerror((err)) | ||
376 | #elif defined(MHD_WINSOCK_SOCKETS) | ||
377 | # define MHD_socket_strerr_(err) MHD_W32_strerror_winsock_((err)) | ||
378 | #endif | ||
266 | 379 | ||
267 | # ifndef EWOULDBLOCK | 380 | /* MHD_socket_last_strerr_ is description string of last errno (non-W32) / |
268 | # define EWOULDBLOCK (MHDW32ERRBASE+1) | 381 | * description string of last socket error (W32) */ |
269 | # endif | 382 | #define MHD_socket_last_strerr_() MHD_socket_strerr_(MHD_socket_get_error_()) |
270 | # ifndef EINPROGRESS | ||
271 | # define EINPROGRESS (MHDW32ERRBASE+2) | ||
272 | # endif | ||
273 | # ifndef EALREADY | ||
274 | # define EALREADY (MHDW32ERRBASE+3) | ||
275 | # endif | ||
276 | # ifndef ENOTSOCK | ||
277 | # define ENOTSOCK (MHDW32ERRBASE+4) | ||
278 | # endif | ||
279 | # ifndef EDESTADDRREQ | ||
280 | # define EDESTADDRREQ (MHDW32ERRBASE+5) | ||
281 | # endif | ||
282 | # ifndef EMSGSIZE | ||
283 | # define EMSGSIZE (MHDW32ERRBASE+6) | ||
284 | # endif | ||
285 | # ifndef EPROTOTYPE | ||
286 | # define EPROTOTYPE (MHDW32ERRBASE+7) | ||
287 | # endif | ||
288 | # ifndef ENOPROTOOPT | ||
289 | # define ENOPROTOOPT (MHDW32ERRBASE+8) | ||
290 | # endif | ||
291 | # ifndef EPROTONOSUPPORT | ||
292 | # define EPROTONOSUPPORT (MHDW32ERRBASE+9) | ||
293 | # endif | ||
294 | # ifndef EOPNOTSUPP | ||
295 | # define EOPNOTSUPP (MHDW32ERRBASE+10) | ||
296 | # endif | ||
297 | # ifndef EAFNOSUPPORT | ||
298 | # define EAFNOSUPPORT (MHDW32ERRBASE+11) | ||
299 | # endif | ||
300 | # ifndef EADDRINUSE | ||
301 | # define EADDRINUSE (MHDW32ERRBASE+12) | ||
302 | # endif | ||
303 | # ifndef EADDRNOTAVAIL | ||
304 | # define EADDRNOTAVAIL (MHDW32ERRBASE+13) | ||
305 | # endif | ||
306 | # ifndef ENETDOWN | ||
307 | # define ENETDOWN (MHDW32ERRBASE+14) | ||
308 | # endif | ||
309 | # ifndef ENETUNREACH | ||
310 | # define ENETUNREACH (MHDW32ERRBASE+15) | ||
311 | # endif | ||
312 | # ifndef ENETRESET | ||
313 | # define ENETRESET (MHDW32ERRBASE+16) | ||
314 | # endif | ||
315 | # ifndef ECONNABORTED | ||
316 | # define ECONNABORTED (MHDW32ERRBASE+17) | ||
317 | # endif | ||
318 | # ifndef ECONNRESET | ||
319 | # define ECONNRESET (MHDW32ERRBASE+18) | ||
320 | # endif | ||
321 | # ifndef ENOBUFS | ||
322 | # define ENOBUFS (MHDW32ERRBASE+19) | ||
323 | # endif | ||
324 | # ifndef EISCONN | ||
325 | # define EISCONN (MHDW32ERRBASE+20) | ||
326 | # endif | ||
327 | # ifndef ENOTCONN | ||
328 | # define ENOTCONN (MHDW32ERRBASE+21) | ||
329 | # endif | ||
330 | # ifndef ETOOMANYREFS | ||
331 | # define ETOOMANYREFS (MHDW32ERRBASE+22) | ||
332 | # endif | ||
333 | # ifndef ECONNREFUSED | ||
334 | # define ECONNREFUSED (MHDW32ERRBASE+23) | ||
335 | # endif | ||
336 | # ifndef ELOOP | ||
337 | # define ELOOP (MHDW32ERRBASE+24) | ||
338 | # endif | ||
339 | # ifndef EHOSTDOWN | ||
340 | # define EHOSTDOWN (MHDW32ERRBASE+25) | ||
341 | # endif | ||
342 | # ifndef EHOSTUNREACH | ||
343 | # define EHOSTUNREACH (MHDW32ERRBASE+26) | ||
344 | # endif | ||
345 | # ifndef EPROCLIM | ||
346 | # define EPROCLIM (MHDW32ERRBASE+27) | ||
347 | # endif | ||
348 | # ifndef EUSERS | ||
349 | # define EUSERS (MHDW32ERRBASE+28) | ||
350 | # endif | ||
351 | # ifndef EDQUOT | ||
352 | # define EDQUOT (MHDW32ERRBASE+29) | ||
353 | # endif | ||
354 | # ifndef ESTALE | ||
355 | # define ESTALE (MHDW32ERRBASE+30) | ||
356 | # endif | ||
357 | # ifndef EREMOTE | ||
358 | # define EREMOTE (MHDW32ERRBASE+31) | ||
359 | # endif | ||
360 | # ifndef ESOCKTNOSUPPORT | ||
361 | # define ESOCKTNOSUPPORT (MHDW32ERRBASE+32) | ||
362 | # endif | ||
363 | # ifndef EPFNOSUPPORT | ||
364 | # define EPFNOSUPPORT (MHDW32ERRBASE+33) | ||
365 | # endif | ||
366 | # ifndef ESHUTDOWN | ||
367 | # define ESHUTDOWN (MHDW32ERRBASE+34) | ||
368 | # endif | ||
369 | # ifndef ENODATA | ||
370 | # define ENODATA (MHDW32ERRBASE+35) | ||
371 | # endif | ||
372 | # ifndef ETIMEDOUT | ||
373 | # define ETIMEDOUT (MHDW32ERRBASE+36) | ||
374 | # endif | ||
375 | 383 | ||
376 | /** | 384 | /** |
377 | * Return errno equivalent of last winsock error | 385 | * MHD_socket_fset_error_() set socket system native error code. |
378 | * @return errno equivalent of last winsock error | ||
379 | */ | 386 | */ |
380 | int MHD_W32_errno_from_winsock_(void); | 387 | #if defined(MHD_POSIX_SOCKETS) |
388 | # define MHD_socket_fset_error_(err) (errno = (err)) | ||
389 | #elif defined(MHD_WINSOCK_SOCKETS) | ||
390 | # define MHD_socket_fset_error_(err) (WSASetLastError((err))) | ||
391 | #endif | ||
381 | 392 | ||
382 | /** | 393 | /** |
383 | * Return pointer to string description of errnum error | 394 | * MHD_socket_try_set_error_() set socket system native error code if |
384 | * Works fine with both standard errno errnums | 395 | * specified code is defined on system. |
385 | * and errnums from MHD_W32_errno_from_winsock_ | 396 | * @return non-zero if specified @a err code is defined on system |
386 | * @param errnum the errno or value from MHD_W32_errno_from_winsock_() | 397 | * and error was set; |
387 | * @return pointer to string description of error | 398 | * zero if specified @a err code is not defined on system |
399 | * and error was not set. | ||
388 | */ | 400 | */ |
389 | const char* MHD_W32_strerror_(int errnum); | 401 | #define MHD_socket_try_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ != (err)) ? \ |
402 | (MHD_socket_fset_error_((err)), !0) : 0 ) | ||
390 | 403 | ||
391 | /** | 404 | /** |
392 | * Return pointer to string description of last winsock error | 405 | * MHD_socket_set_error_() set socket system native error code to |
393 | * @return pointer to string description of last winsock error | 406 | * specified code or replacement code if specified code is not |
407 | * defined on system. | ||
394 | */ | 408 | */ |
395 | const char* MHD_W32_strerror_last_winsock_(void); | 409 | #if defined(MHD_POSIX_SOCKETS) |
410 | # if defined(ENOSYS) | ||
411 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | ||
412 | (errno = ENOSYS) : (errno = (err)) ) | ||
413 | # elif defined(EOPNOTSUPP) | ||
414 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | ||
415 | (errno = EOPNOTSUPP) : (errno = (err)) ) | ||
416 | # elif defined (EFAULT) | ||
417 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | ||
418 | (errno = EFAULT) : (errno = (err)) ) | ||
419 | # elif defined (EINVAL) | ||
420 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | ||
421 | (errno = EINVAL) : (errno = (err)) ) | ||
422 | # else /* !EOPNOTSUPP && !EFAULT && !EINVAL */ | ||
423 | # warning No suitable replacement for missing socket error code is found. Edit this file and add replacement code which is defined on system. | ||
424 | # define MHD_socket_set_error_(err) (errno = (err)) | ||
425 | # endif /* !EOPNOTSUPP && !EFAULT && !EINVAL*/ | ||
426 | #elif defined(MHD_WINSOCK_SOCKETS) | ||
427 | # define MHD_socket_set_error_(err) ( (MHD_SCKT_MISSING_ERR_CODE_ == (err)) ? \ | ||
428 | (WSASetLastError((WSAEOPNOTSUPP))) : \ | ||
429 | (WSASetLastError((err))) ) | ||
430 | #endif | ||
396 | 431 | ||
397 | /** | 432 | /** |
398 | * Set last winsock error to equivalent of given errno value | 433 | * Check whether given socket error is equal to specified system |
399 | * @param errnum the errno value to set | 434 | * native MHD_SCKT_E*_ code. |
435 | * If platform don't have specific error code, result is | ||
436 | * always boolean false. | ||
437 | * @return boolean true if @a code is real error code and | ||
438 | * @a err equals to MHD_SCKT_E*_ @a code; | ||
439 | * boolean false otherwise | ||
400 | */ | 440 | */ |
401 | void MHD_W32_set_last_winsock_error_(int errnum); | 441 | #define MHD_SCKT_ERR_IS_(err,code) ( (MHD_SCKT_MISSING_ERR_CODE_ != (code)) && \ |
442 | ((code) == (err)) ) | ||
402 | 443 | ||
444 | /** | ||
445 | * Check whether last socket error is equal to specified system | ||
446 | * native MHD_SCKT_E*_ code. | ||
447 | * If platform don't have specific error code, result is | ||
448 | * always boolean false. | ||
449 | * @return boolean true if @a code is real error code and | ||
450 | * last socket error equals to MHD_SCKT_E*_ @a code; | ||
451 | * boolean false otherwise | ||
452 | */ | ||
453 | #define MHD_SCKT_LAST_ERR_IS_(code) MHD_SCKT_ERR_IS_(MHD_socket_get_error_() ,(code)) | ||
403 | 454 | ||
404 | #endif /* MHD_WINSOCK_SOCKETS */ | 455 | /* Specific error code checks */ |
456 | |||
457 | /** | ||
458 | * Check whether given socket error is equal to system's | ||
459 | * socket error codes for EINTR. | ||
460 | * @return boolean true if @a err is equal to sockets' EINTR code; | ||
461 | * boolean false otherwise. | ||
462 | */ | ||
463 | #define MHD_SCKT_ERR_IS_EINTR_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EINTR_) | ||
464 | |||
465 | /** | ||
466 | * Check whether given socket error is equal to system's | ||
467 | * socket error codes for EAGAIN or EWOULDBLOCK. | ||
468 | * @return boolean true if @a err is equal to sockets' EAGAIN or EWOULDBLOCK codes; | ||
469 | * boolean false otherwise. | ||
470 | */ | ||
471 | #if MHD_SCKT_EAGAIN_ == MHD_SCKT_EWOULDBLOCK_ | ||
472 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) | ||
473 | #else /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ | ||
474 | # define MHD_SCKT_ERR_IS_EAGAIN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EAGAIN_) || \ | ||
475 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_EWOULDBLOCK_) ) | ||
476 | #endif /* MHD_SCKT_EAGAIN_ != MHD_SCKT_EWOULDBLOCK_ */ | ||
477 | |||
478 | /** | ||
479 | * Check whether given socket error is any kind of "low resource" error. | ||
480 | * @return boolean true if @a err is any kind of "low resource" error, | ||
481 | * boolean false otherwise. | ||
482 | */ | ||
483 | #define MHD_SCKT_ERR_IS_LOW_RESOURCES_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_EMFILE_) || \ | ||
484 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENFILE_) || \ | ||
485 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOMEM_) || \ | ||
486 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_ENOBUFS_) ) | ||
487 | |||
488 | /** | ||
489 | * Check whether is given socket error is type of "incoming connection | ||
490 | * was disconnected before 'accept()' is called". | ||
491 | * @return boolean true is @a err match described socket error code, | ||
492 | * boolean false otherwise. | ||
493 | */ | ||
494 | #if defined(MHD_POSIX_SOCKETS) | ||
495 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_) | ||
496 | #elif defined(MHD_WINSOCK_SOCKETS) | ||
497 | # define MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_(err) MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) | ||
498 | #endif | ||
499 | |||
500 | /** | ||
501 | * Check whether is given socket error is type of "connection was terminated | ||
502 | * by remote side". | ||
503 | * @return boolean true is @a err match described socket error code, | ||
504 | * boolean false otherwise. | ||
505 | */ | ||
506 | #define MHD_SCKT_ERR_IS_REMOTE_DISCNN_(err) ( MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNRESET_) || \ | ||
507 | MHD_SCKT_ERR_IS_((err),MHD_SCKT_ECONNABORTED_)) | ||
508 | |||
509 | /* Specific error code set */ | ||
510 | |||
511 | /** | ||
512 | * Set socket's error code to ENOMEM or equivalent if ENOMEM is not | ||
513 | * available on platform. | ||
514 | */ | ||
515 | #if MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOMEM_ | ||
516 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) | ||
517 | #elif MHD_SCKT_MISSING_ERR_CODE_ != MHD_SCKT_ENOBUFS_ | ||
518 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOBUFS_) | ||
519 | #else | ||
520 | # warning No suitable replacement for ENOMEM error codes is found. Edit this file and add replacement code which is defined on system. | ||
521 | # define MHD_socket_set_error_to_ENOMEM() MHD_socket_set_error_(MHD_SCKT_ENOMEM_) | ||
522 | #endif | ||
405 | 523 | ||
406 | #endif /* ! MHD_SOCKETS_H */ | 524 | #endif /* ! MHD_SOCKETS_H */ |