MySQL 8.0.39
Source Code Documentation
socket_operations.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_HARNESS_SOCKETOPERATIONS_INCLUDED
27#define MYSQL_HARNESS_SOCKETOPERATIONS_INCLUDED
28
29#include <stdexcept>
30#include <string>
31#include <system_error>
32
33#include "harness_export.h"
35
36namespace mysql_harness {
37
40
41/** @class SocketOperationsBase
42 * @brief Base class to allow multiple SocketOperations implementations
43 * (at least one "real" and one mock for testing purposes)
44 */
45class HARNESS_EXPORT SocketOperationsBase {
46 public:
47 explicit SocketOperationsBase() = default;
48 explicit SocketOperationsBase(const SocketOperationsBase &) = default;
50 virtual ~SocketOperationsBase() = default;
51
52 /** @brief Exception thrown by `get_local_hostname()` on error */
53 class LocalHostnameResolutionError : public std::runtime_error {
54 using std::runtime_error::runtime_error;
55 };
56
57 /** @brief return hostname of local host */
58 virtual std::string get_local_hostname() = 0;
59};
60
61/** @class SocketOperations
62 * @brief This class provides a "real" (not mock) implementation
63 */
64class HARNESS_EXPORT SocketOperations : public SocketOperationsBase {
65 public:
66 static SocketOperations *instance();
67
70 /** @brief return hostname of local host
71 *
72 * @throws `LocalHostnameResolutionError` (std::runtime_error) on failure
73 */
74 std::string get_local_hostname() override;
75
76 private:
77 SocketOperations() = default;
78};
79
80} // namespace mysql_harness
81
82#endif // MYSQL_HARNESS_SOCKETOPERATIONS_INCLUDED
Exception thrown by get_local_hostname() on error.
Definition: socket_operations.h:53
Base class to allow multiple SocketOperations implementations (at least one "real" and one mock for t...
Definition: socket_operations.h:45
virtual ~SocketOperationsBase()=default
virtual std::string get_local_hostname()=0
return hostname of local host
SocketOperationsBase & operator=(const SocketOperationsBase &)=default
SocketOperationsBase(const SocketOperationsBase &)=default
This class provides a "real" (not mock) implementation.
Definition: socket_operations.h:64
SocketOperations(const SocketOperations &)=delete
SocketOperations operator=(const SocketOperations &)=delete
Definition: common.h:42
net::impl::socket::native_handle_type socket_t
Definition: socket_operations.h:38
constexpr socket_t kInvalidSocket
Definition: socket_operations.h:39
int native_handle_type
Definition: socket_constants.h:51
constexpr const native_handle_type kInvalidSocket
Definition: socket_constants.h:52