MySQL 8.0.29
Source Code Documentation
socket_operations.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2021, 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 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 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 MYSQL_HARNESS_SOCKETOPERATIONS_INCLUDED
26#define MYSQL_HARNESS_SOCKETOPERATIONS_INCLUDED
27
28#include <stdexcept>
29#include <string>
30#include <system_error>
31
32#include "harness_export.h"
34
35namespace mysql_harness {
36
39
40/** @class SocketOperationsBase
41 * @brief Base class to allow multiple SocketOperations implementations
42 * (at least one "real" and one mock for testing purposes)
43 */
44class HARNESS_EXPORT SocketOperationsBase {
45 public:
46 explicit SocketOperationsBase() = default;
47 explicit SocketOperationsBase(const SocketOperationsBase &) = default;
49 virtual ~SocketOperationsBase() = default;
50
51 /** @brief Exception thrown by `get_local_hostname()` on error */
52 class LocalHostnameResolutionError : public std::runtime_error {
53 using std::runtime_error::runtime_error;
54 };
55
56 /** @brief return hostname of local host */
57 virtual std::string get_local_hostname() = 0;
58};
59
60/** @class SocketOperations
61 * @brief This class provides a "real" (not mock) implementation
62 */
63class HARNESS_EXPORT SocketOperations : public SocketOperationsBase {
64 public:
65 static SocketOperations *instance();
66
69 /** @brief return hostname of local host
70 *
71 * @throws `LocalHostnameResolutionError` (std::runtime_error) on failure
72 */
73 std::string get_local_hostname() override;
74
75 private:
76 SocketOperations() = default;
77};
78
79} // namespace mysql_harness
80
81#endif // MYSQL_HARNESS_SOCKETOPERATIONS_INCLUDED
Exception thrown by get_local_hostname() on error.
Definition: socket_operations.h:52
Base class to allow multiple SocketOperations implementations (at least one "real" and one mock for t...
Definition: socket_operations.h:44
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:63
SocketOperations(const SocketOperations &)=delete
SocketOperations operator=(const SocketOperations &)=delete
Definition: common.h:41
net::impl::socket::native_handle_type socket_t
Definition: socket_operations.h:37
constexpr socket_t kInvalidSocket
Definition: socket_operations.h:38
int native_handle_type
Definition: socket_constants.h:50
constexpr const native_handle_type kInvalidSocket
Definition: socket_constants.h:51