Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
Socket.h
1 /*
2  * Copyright (c) 2008-2015, 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_SOCKET
17 #define HAZELCAST_SOCKET
18 
19 
20 #include "hazelcast/client/Address.h"
21 #include "hazelcast/util/AtomicBoolean.h"
22 #include <string>
23 
24 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25 #pragma warning(push)
26 #pragma warning(disable: 4251) //for dll export
27 #endif
28 
29 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
30 #pragma comment(lib, "Ws2_32.lib")
31 #include <winsock2.h>
32 #include <ws2tcpip.h>
33 #else
34 
35 #include <unistd.h>
36 #include <netdb.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41 #include <sys/wait.h>
42 #include <sys/errno.h>
43 #include <sys/select.h>
44 #include <fcntl.h>
45 
46 #endif
47 
48 
49 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
50  typedef int socklen_t;
51 #endif
52 
53 #if !defined(MSG_NOSIGNAL)
54 # define MSG_NOSIGNAL 0
55 #endif
56 
57 namespace hazelcast {
58  namespace client {
62  class HAZELCAST_API Socket {
63  public:
67  Socket(int socketId);
71  Socket(const client::Address &address);
75  virtual ~Socket();
81  int connect(int timeoutInMillis);
82 
89  virtual int send(const void *buffer, int len) const;
90 
98  int receive(void *buffer, int len, int flag = 0) const;
99 
103  int getSocketId() const;
104 
108  void setRemoteEndpoint(const client::Address &address);
109 
113  const client::Address &getRemoteEndpoint() const;
118  void close();
119 
120  client::Address getAddress() const;
121 
122  void setBlocking(bool blocking);
123 
124  private:
125 
126  Socket(const Socket &rhs);
127 
128  Socket& operator=(const Socket &rhs);
129 
130  client::Address remoteEndpoint;
131 
132  struct addrinfo *serverInfo;
133  int socketId;
134  util::AtomicBoolean isOpen;
135 
136  #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
137  WSADATA wsa_data;
138  #endif
139 
140  };
141 
145  struct HAZELCAST_API socketPtrComp {
149  bool operator ()(Socket const *const &lhs, Socket const *const &rhs) const;
150  };
151 
152  }
153 }
154 
155 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
156 #pragma warning(pop)
157 #endif
158 
159 #endif /* HAZELCAST_SOCKET */
Socket Ptr compare method.
Definition: Socket.h:145
IP Address.
Definition: Address.h:36
c Sockets wrapper class.
Definition: Socket.h:62