Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
socket_interceptor.h
1/*
2 * Copyright (c) 2008-2025, Hazelcast, Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <functional>
19#include <utility>
20
21#include "hazelcast/util/export.h"
22#include "hazelcast/util/noop.h"
23#include "hazelcast/util/type_traits.h"
24
25#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
26#pragma warning(push)
27#pragma warning(disable : 4251) // for dll export
28#endif
29
30namespace hazelcast {
31namespace client {
32class socket;
33
34namespace connection {
35class ClientConnectionManagerImpl;
36}
37
43class HAZELCAST_API socket_interceptor final
44{
45public:
52 template<typename Handler,
53 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
55 {
56 connect_ = std::forward<Handler>(h);
57 return *this;
58 }
59
63 template<typename Handler,
64 typename = util::enable_if_rvalue_ref_trait<Handler&&>>
66 {
67 on_connect(std::forward<Handler>(h));
68 return std::move(*this);
69 }
70
71private:
72 friend class connection::ClientConnectionManagerImpl;
73
74 using handler_t = std::function<void(const socket&)>;
75
76 handler_t connect_{ util::noop<const socket&> };
77};
78} // namespace client
79} // namespace hazelcast
80
81#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
82#pragma warning(pop)
83#endif
An interface that provides the ability to intercept the creation of sockets.
socket_interceptor & on_connect(Handler &&h) &
Set an handler function that will be called with a Socket, each time the client creates a connection ...
socket_interceptor && on_connect(Handler &&h) &&