Hazelcast C++ Client
 All Classes Functions Variables Enumerations Enumerator Pages
SSLSocket.h
1 /*
2  * Copyright (c) 2008-2017, 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 #ifndef HAZELCAST_CLIENT_INTERNAL_SOCKET_SSLSOCKET_H_
17 #define HAZELCAST_CLIENT_INTERNAL_SOCKET_SSLSOCKET_H_
18 
19 #ifdef HZ_BUILD_WITH_SSL
20 
21 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
22 #pragma warning(push)
23 #pragma warning(disable: 4251) //for dll export
24 #endif
25 
26 #include <asio.hpp>
27 #include <asio/ssl.hpp>
28 
29 #include "hazelcast/client/Socket.h"
30 #include "hazelcast/client/Address.h"
31 #include "hazelcast/util/AtomicBoolean.h"
32 
33 #if !defined(MSG_NOSIGNAL)
34 # define MSG_NOSIGNAL 0
35 #endif
36 
37 namespace hazelcast {
38  namespace client {
39  namespace internal {
40  namespace socket {
44  class HAZELCAST_API SSLSocket : public Socket {
45  public:
46  struct CipherInfo {
47  std::string name;
48  int numberOfBits;
49  std::string version;
50  std::string description;
51  };
52 
56  SSLSocket(const client::Address &address, asio::io_service &ioService,
57  asio::ssl::context &sslContext);
58 
62  virtual ~SSLSocket();
63 
69  int connect(int timeoutInMillis);
70 
77  int send(const void *buffer, int len) const;
78 
86  int receive(void *buffer, int len, int flag = 0) const;
87 
91  int getSocketId() const;
92 
96  void setRemoteEndpoint(const client::Address &address);
97 
101  const client::Address &getRemoteEndpoint() const;
102 
107  void close();
108 
109  client::Address getAddress() const;
110 
111  void setBlocking(bool blocking);
112 
116  std::vector<SSLSocket::CipherInfo> getCiphers() const;
117  private:
118  SSLSocket(const Socket &rhs);
119 
120  SSLSocket &operator=(const Socket &rhs);
121 
126  int handleError(const std::string &source, size_t numBytes, const asio::error_code &error) const;
127 
128  void startTimer();
129 
130  client::Address remoteEndpoint;
131 
132  util::AtomicBoolean isOpen;
133 
134  asio::io_service &ioService;
135  asio::ssl::context &sslContext;
136  std::auto_ptr<asio::ssl::stream<asio::ip::tcp::socket> > socket;
137  asio::deadline_timer deadline;
138  };
139 
140  std::ostream &operator<<(std::ostream &out, const SSLSocket::CipherInfo &info);
141  }
142  }
143  }
144 }
145 
146 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
147 #pragma warning(pop)
148 #endif
149 
150 #endif /* HZ_BUILD_WITH_SSL */
151 
152 #endif /* HAZELCAST_CLIENT_INTERNAL_SOCKET_SSLSOCKET_H_ */