Hazelcast C++ Client
Hazelcast C++ Client Library
socket_interceptor.h
1 /*
2  * Copyright (c) 2008-2021, 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  public:
50  template<typename Handler,
51  typename = util::enable_if_rvalue_ref_t<Handler &&>>
52  socket_interceptor &on_connect(Handler &&h) & {
53  connect_ = std::forward<Handler>(h);
54  return *this;
55  }
56 
60  template<typename Handler,
61  typename = util::enable_if_rvalue_ref_t<Handler &&>>
62  socket_interceptor &&on_connect(Handler &&h) && {
63  on_connect(std::forward<Handler>(h));
64  return std::move(*this);
65  }
66 
67 
68  private:
69  friend class connection::ClientConnectionManagerImpl;
70 
71  using handler_t = std::function<void(const socket &)>;
72 
73  handler_t connect_{util::noop<const socket &>};
74  };
75  }
76 }
77 
78 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
79 #pragma warning(pop)
80 #endif
81 
82 
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) &&