MySQL 9.0.0
Source Code Documentation
node_connection.h
Go to the documentation of this file.
1/* Copyright (c) 2012, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
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#ifndef NODE_CONNECTION_H
25#define NODE_CONNECTION_H
26
27#include <stdlib.h>
28
29#ifndef XCOM_WITHOUT_OPENSSL
30#ifdef _WIN32
31/* In OpenSSL before 1.1.0, we need this first. */
32#include <winsock2.h>
33#endif
34
35#include <openssl/ssl.h>
36
37#endif
38
40#include "xcom/xcom_memory.h"
41#include "xcom/xcom_proto.h"
42#include "xdr_gen/xcom_vp.h"
43
45typedef enum con_state con_state;
46
48 int fd;
49#ifndef XCOM_WITHOUT_OPENSSL
50 SSL *ssl_fd;
51#endif
53 unsigned int snd_tag;
54 xcom_proto x_proto;
56};
57
59
60#ifndef XCOM_WITHOUT_OPENSSL
61static inline connection_descriptor *new_connection(int fd, SSL *ssl_fd) {
63 (size_t)1, sizeof(connection_descriptor));
64 c->fd = fd;
65 c->ssl_fd = ssl_fd;
67 return c;
68}
69#else
70static inline connection_descriptor *new_connection(int fd) {
72 (size_t)1, sizeof(connection_descriptor));
73 c->fd = fd;
75 return c;
76}
77#endif
78
79/**
80 * @brief Free a connection_descriptor created with new_connection.
81 * This function will, if the [in] parameter is not nullptr:
82 * - Free the pointer
83 * - Set the pointer to nullptr
84 *
85 * @param con a pointer to a connection_descriptor.
86 */
87static inline void free_connection(connection_descriptor *&con) {
88 if (con != nullptr) {
89 free(con);
90 con = nullptr;
91 }
92}
93
94static inline int is_connected(connection_descriptor *con) {
95 return con->connected_ >= CON_FD;
96}
97
98static inline int proto_done(connection_descriptor *con) {
99 return con->connected_ == CON_PROTO;
100}
101
102static inline void set_connected(connection_descriptor *con, con_state val) {
103 con->connected_ = val;
104}
105
108 con->protocol_stack = val;
109}
110
111#endif /* NODE_CONNECTION_H */
#define free(A)
Definition: lexyy.cc:915
enum_transport_protocol
Enum that describes the available XCom Communication Stacks.
Definition: network_provider.h:45
con_state
Definition: node_connection.h:44
@ CON_NULL
Definition: node_connection.h:44
@ CON_PROTO
Definition: node_connection.h:44
@ CON_FD
Definition: node_connection.h:44
static void free_connection(connection_descriptor *&con)
Free a connection_descriptor created with new_connection.
Definition: node_connection.h:87
static void set_connected(connection_descriptor *con, con_state val)
Definition: node_connection.h:102
static int proto_done(connection_descriptor *con)
Definition: node_connection.h:98
struct connection_descriptor connection_descriptor
Definition: node_connection.h:58
static int is_connected(connection_descriptor *con)
Definition: node_connection.h:94
static void set_protocol_stack(connection_descriptor *con, enum_transport_protocol val)
Definition: node_connection.h:106
static connection_descriptor * new_connection(int fd, SSL *ssl_fd)
Definition: node_connection.h:61
Definition: node_connection.h:47
xcom_proto x_proto
Definition: node_connection.h:54
enum_transport_protocol protocol_stack
Definition: node_connection.h:55
con_state connected_
Definition: node_connection.h:52
int fd
Definition: node_connection.h:48
SSL * ssl_fd
Definition: node_connection.h:50
unsigned int snd_tag
Definition: node_connection.h:53
static void * xcom_calloc(size_t nmemb, size_t size)
Definition: xcom_memory.h:54