Hazelcast C++ Client
Hazelcast C++ Client Library
socket_interceptor.h
1 /*
2  * Copyright (c) 2008-2022, 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 
30 namespace hazelcast {
31 namespace client {
32 class socket;
33 
34 namespace connection {
35 class ClientConnectionManagerImpl;
36 }
37 
43 class HAZELCAST_API socket_interceptor final
44 {
45 public:
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&&>>
65  socket_interceptor&& on_connect(Handler&& h) &&
66  {
67  on_connect(std::forward<Handler>(h));
68  return std::move(*this);
69  }
70 
71 private:
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) &&