d1a339638a3487e76982bfafc26bb270df28e13b
[m6w6/libmemcached] / src / libmemcached / socket.hpp
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #pragma once
17
18 /* To hide the platform differences between MS Windows and Unix, I am
19 * going to use the Microsoft way and #define the Microsoft-specific
20 * functions to the unix way. Microsoft use a separate subsystem for sockets,
21 * but Unix normally just use a filedescriptor on the same functions. It is
22 * a lot easier to map back to the unix way with macros than going the other
23 * way without side effect ;-)
24 */
25 #if defined(WIN32) || defined(__MINGW32__)
26 # include "win32/wrappers.h"
27 # define get_socket_errno() WSAGetLastError()
28 #else
29 # include <unistd.h>
30 # define INVALID_SOCKET -1
31 # define SOCKET_ERROR -1
32 # define closesocket(a) close(a)
33 # define get_socket_errno() errno
34 #endif
35
36 #ifdef __cplusplus
37 static inline void memcached_close_socket(memcached_socket_t &socket_fd) {
38 closesocket(socket_fd);
39 socket_fd = INVALID_SOCKET;
40 }
41 #endif
42
43 #ifndef HAVE_MSG_NOSIGNAL
44 # define MSG_NOSIGNAL 0
45 #endif
46
47 #ifndef HAVE_MSG_DONTWAIT
48 # define MSG_DONTWAIT 0
49 #endif
50
51 #ifndef HAVE_MSG_MORE
52 # define MSG_MORE 0
53 #endif