Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "hazelcast/util/HazelcastDll.h"
#include "hazelcast/client/config/SSLConfig.h"
#include "hazelcast/client/config/ClientAwsConfig.h"
#include "hazelcast/client/config/SocketOptions.h"

#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#pragma warning(push)
Expand Down Expand Up @@ -180,6 +181,8 @@ namespace hazelcast {
*/
ClientNetworkConfig &addAddress(const Address &address);

SocketOptions &getSocketOptions();

private:
static int32_t CONNECTION_ATTEMPT_PERIOD;

Expand All @@ -194,6 +197,7 @@ namespace hazelcast {

std::vector<Address> addressList;

SocketOptions socketOptions;
};
}
}
Expand Down
153 changes: 153 additions & 0 deletions hazelcast/include/hazelcast/client/config/SocketOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HAZELCAST_CLIENT_CONFIG_SOCKETOPTIONS_H_
#define HAZELCAST_CLIENT_CONFIG_SOCKETOPTIONS_H_

#include "hazelcast/util/HazelcastDll.h"

#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#pragma warning(push)
#pragma warning(disable: 4251) //for dll export
#endif

namespace hazelcast {
namespace client {
namespace config {
/**
* TCP Socket options
*/
class HAZELCAST_API SocketOptions {
public:
/**
* constant for kilobyte

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we dont need this comment, it doesnt say more than the variable name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are from Java client documentation. If needed we need to change both. I think it can stay.

Copy link

@SaitTalhaNisanci SaitTalhaNisanci Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are not even used in Java :) I sent a cleanup PR for that https://github.com/hazelcast/hazelcast/pull/14147/files

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As they are part of API we cant change them I guess. If there isnt any check like checkstyle for CPP we shouldnt have them here. They are probably there in Java because of checkstyle(otherwise the build fails).

*/
static const int KILO_BYTE = 1024;

/**
* default buffer size of Bytes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
static const int DEFAULT_BUFFER_SIZE_BYTE = 128 * KILO_BYTE;

SocketOptions();

/**
* TCP_NODELAY socket option
*
* @return true if enabled
*/
bool isTcpNoDelay() const;

/**
* Enable/disable TCP_NODELAY socket option.
*
* @param tcpNoDelay
*/
SocketOptions &setTcpNoDelay(bool tcpNoDelay);

/**
* SO_KEEPALIVE socket option
*
* @return true if enabled
*/
bool isKeepAlive() const;

/**
* Enable/disable SO_KEEPALIVE socket option.
*
* @param keepAlive enabled if true
* @return SocketOptions configured
*/
SocketOptions &setKeepAlive(bool keepAlive);

/**
* SO_REUSEADDR socket option.
*
* @return true if enabled
*/
bool isReuseAddress() const;

/**
* Enable/disable the SO_REUSEADDR socket option.
*
* @param reuseAddress enabled if true
* @return SocketOptions configured
*/
SocketOptions &setReuseAddress(bool reuseAddress);

/**
* Gets SO_LINGER with the specified linger time in seconds
* @return lingerSeconds value in seconds
*/
int getLingerSeconds() const;

/**
* Enable/disable SO_LINGER with the specified linger time in seconds

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What value disables SO_LINGER?

Copy link
Collaborator Author

@ihsandemir ihsandemir Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added doc:

                *
                 * if set to a value of 0 or less then it is disabled.
                 *
                 * Default value is 3.

*
* if set to a value of 0 or less then it is disabled.
*
* Default value is 3.
*
* @param lingerSeconds value in seconds
* @return SocketOptions configured
*/
SocketOptions &setLingerSeconds(int lingerSeconds);

/**
* If set to 0 or less, then it is not set on the socket.
*
* The default value is DEFAULT_BUFFER_SIZE_BYTE
*
* Gets the SO_SNDBUF and SO_RCVBUF options value in bytes
* @return bufferSize Number of bytes
*/
int getBufferSizeInBytes() const;

/**
* If set to 0 or less, then it is not set on the socket.
*
* The default value is DEFAULT_BUFFER_SIZE_BYTE
*
* Sets the SO_SNDBUF and SO_RCVBUF options to the specified value in bytes
*
* @param bufferSize Number of bytes
* @return SocketOptions configured
*/
SocketOptions &setBufferSizeInBytes(int bufferSize);

private:
// socket options

bool tcpNoDelay;

bool keepAlive;

bool reuseAddress;

int lingerSeconds;

int bufferSize;

};

}
}
}

#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#pragma warning(pop)
#endif

#endif /* HAZELCAST_CLIENT_CONFIG_SOCKETOPTIONS_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace hazelcast {
namespace client {
class Socket;

namespace config {
class SocketOptions;
}
namespace connection {
class ListenerTask;

Expand All @@ -47,7 +50,7 @@ namespace hazelcast {

class HAZELCAST_API IOSelector : public util::Runnable {
public:
IOSelector(ClientConnectionManagerImpl &connectionManager);
IOSelector(ClientConnectionManagerImpl &connectionManager, const config::SocketOptions &socketOptions);

virtual ~IOSelector();

Expand Down Expand Up @@ -89,6 +92,7 @@ namespace hazelcast {
std::auto_ptr<Socket> wakeUpSocket;
util::ConcurrentQueue<ListenerTask> listenerTasks;
util::AtomicBoolean isAlive;
const config::SocketOptions &socketOptions;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace hazelcast {
namespace connection {
class HAZELCAST_API InSelector : public IOSelector {
public:
InSelector(ClientConnectionManagerImpl &connectionManager);
InSelector(ClientConnectionManagerImpl &connectionManager, const config::SocketOptions &socketOptions);

void listenInternal();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace hazelcast {
namespace connection {
class HAZELCAST_API OutSelector : public IOSelector {
public:
OutSelector(ClientConnectionManagerImpl &connectionManager);
OutSelector(ClientConnectionManagerImpl &connectionManager, const config::SocketOptions &socketOptions);

void listenInternal();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "hazelcast/client/Socket.h"
#include "hazelcast/client/Address.h"
#include "hazelcast/client/config/SocketOptions.h"
#include "hazelcast/util/AtomicBoolean.h"

#if !defined(MSG_NOSIGNAL)
Expand Down Expand Up @@ -54,7 +55,8 @@ namespace hazelcast {
/**
* Constructor
*/
SSLSocket(const client::Address &address, asio::ssl::context &sslContext);
SSLSocket(const client::Address &address, asio::ssl::context &sslContext,
client::config::SocketOptions &socketOptions);

/**
* Destructor
Expand Down Expand Up @@ -107,6 +109,7 @@ namespace hazelcast {
std::vector<SSLSocket::CipherInfo> getCiphers() const;

std::auto_ptr<Address> localSocketAddress() const;

private:
SSLSocket(const Socket &rhs);

Expand Down Expand Up @@ -137,6 +140,8 @@ namespace hazelcast {

void checkDeadline(const asio::error_code &ec);

void setSocketOptions();

client::Address remoteEndpoint;

asio::io_service ioService;
Expand All @@ -145,6 +150,7 @@ namespace hazelcast {
asio::deadline_timer deadline;
asio::error_code errorCode;
int socketId;
const client::config::SocketOptions &socketOptions;
};

std::ostream &operator<<(std::ostream &out, const SSLSocket::CipherInfo &info);
Expand Down
15 changes: 10 additions & 5 deletions hazelcast/include/hazelcast/client/internal/socket/TcpSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ typedef int socklen_t;
#include <sys/errno.h>
#include <sys/select.h>
#include <fcntl.h>
#include <netinet/tcp.h>

#endif

#include "hazelcast/client/Socket.h"
#include <string>
#include <boost/shared_ptr.hpp>

#include "hazelcast/client/Socket.h"
#include "hazelcast/client/config/SocketOptions.h"
#include "hazelcast/client/Address.h"
#include "hazelcast/util/AtomicBoolean.h"
#include <string>
#include <boost/shared_ptr.hpp>

#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#pragma warning(push)
#pragma warning(disable: 4251) //for dll export
#pragma warning(disable: 4251) //for dll export
#endif

#if !defined(MSG_NOSIGNAL)
Expand All @@ -71,7 +73,7 @@ namespace hazelcast {
/**
* Constructor
*/
TcpSocket(const client::Address &address);
TcpSocket(const client::Address &address, const client::config::SocketOptions *socketOptions);

/**
* Destructor
Expand Down Expand Up @@ -119,6 +121,7 @@ namespace hazelcast {
void setBlocking(bool blocking);

std::auto_ptr<Address> localSocketAddress() const;

private:
TcpSocket(const Socket &rhs);

Expand All @@ -128,6 +131,8 @@ namespace hazelcast {

void throwIOException(int error, const char *methodName, const char *prefix) const;

void setSocketOptions(const client::config::SocketOptions &socketOptions);

const Address configAddress;

struct addrinfo *serverInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ namespace hazelcast {
addressList.push_back(address);
return *this;
}

SocketOptions &ClientNetworkConfig::getSocketOptions() {
return socketOptions;
}
}
}
}
Loading