1 /*
2    Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef NDB_SOCKET_H
26 #define NDB_SOCKET_H
27 
28 #ifdef _WIN32
29 #include "ndb_socket_win32.h"
30 #else
31 #include "ndb_socket_posix.h"
32 #endif
33 
34 
35 static inline
36 void ndb_socket_close_with_reset(ndb_socket_t sock, bool with_reset = false)
37 {
38   if (with_reset)
39   {
40     // Force hard reset of the socket by turning on linger
41     // with timeout 0
42     struct linger hard_reset = {1, 0};
43     ndb_setsockopt(sock, SOL_SOCKET, SO_LINGER,
44                   (void*)&hard_reset, sizeof(hard_reset));
45   }
46 
47   ndb_socket_close(sock);
48 }
49 
50 // Create ndb_socket_t given ndb_native_socket_t
51 static inline
ndb_socket_create_from_native(ndb_native_socket_t native_socket)52 ndb_socket_t ndb_socket_create_from_native(ndb_native_socket_t native_socket)
53 {
54   ndb_socket_t s;
55 #ifdef _WIN32
56   s.s = native_socket;
57 #else
58   s.fd = native_socket;
59 #endif
60   return s;
61 }
62 
63 /*
64   create a pair of connected sockets
65 */
66 int ndb_socketpair(ndb_socket_t s[2]);
67 
68 #endif
69