Hazelcast C++ Client
TcpSocket.h
1 /*
2  * Copyright (c) 2008-2018, 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_TCPSOCKET_H_
17 #define HAZELCAST_CLIENT_INTERNAL_SOCKET_TCPSOCKET_H_
18 
19 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
20 #pragma comment(lib, "Ws2_32.lib")
21 #include <winsock2.h>
22 #include <ws2tcpip.h>
23 
24 typedef int socklen_t;
25 
26 #else
27 
28 #include <unistd.h>
29 #include <netdb.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #include <sys/wait.h>
35 #include <sys/errno.h>
36 #include <sys/select.h>
37 #include <fcntl.h>
38 
39 #endif
40 
41 #include "hazelcast/client/Socket.h"
42 
43 #include "hazelcast/client/Address.h"
44 #include "hazelcast/util/AtomicBoolean.h"
45 #include <string>
46 #include <boost/shared_ptr.hpp>
47 
48 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
49 #pragma warning(push)
50 #pragma warning(disable: 4251) //for dll export
51 #endif
52 
53 #if !defined(MSG_NOSIGNAL)
54 # define MSG_NOSIGNAL 0
55 #endif
56 
57 namespace hazelcast {
58  namespace client {
59  namespace internal {
60  namespace socket {
64  class HAZELCAST_API TcpSocket : public Socket {
65  public:
69  TcpSocket(int socketId);
70 
74  TcpSocket(const client::Address &address);
75 
79  virtual ~TcpSocket();
80 
86  int connect(int timeoutInMillis);
87 
95  int send(const void *buffer, int len, int flag = 0);
96 
104  int receive(void *buffer, int len, int flag = 0);
105 
109  int getSocketId() const;
110 
115  void close();
116 
117  Address getAddress() const;
118 
119  void setBlocking(bool blocking);
120 
121  std::auto_ptr<Address> localSocketAddress() const;
122  private:
123  TcpSocket(const Socket &rhs);
124 
125  TcpSocket &operator=(const Socket &rhs);
126 
127  void throwIOException(const char *methodName, const char *prefix) const;
128 
129  void throwIOException(int error, const char *methodName, const char *prefix) const;
130 
131  const Address configAddress;
132 
133  struct addrinfo *serverInfo;
134  int socketId;
135  util::AtomicBoolean isOpen;
136 
137  #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
138  WSADATA wsa_data;
139  #endif
140  };
141  }
142  }
143  }
144 }
145 
146 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
147 #pragma warning(pop)
148 #endif
149 
150 #endif /* HAZELCAST_CLIENT_INTERNAL_SOCKET_TCPSOCKET_H_ */
IP Address.
Definition: Address.h:41
Sockets wrapper interface class.
Definition: Socket.h:34
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
c Sockets wrapper class.
Definition: TcpSocket.h:64