Skip to content

Add support for Socket SO_TIMEOUT #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -48,6 +48,7 @@
@ThreadSafe
public class TcpSyslogMessageSender extends AbstractSyslogMessageSender implements Closeable {
public final static int SETTING_SOCKET_CONNECT_TIMEOUT_IN_MILLIS_DEFAULT_VALUE = 500;
public final static int SETTING_SOCKET_SO_TIMEOUT_IN_MILLIS_DEFAULT_VALUE = 0;
public final static int SETTING_MAX_RETRY = 2;

/**
Expand All @@ -68,6 +69,7 @@ public class TcpSyslogMessageSender extends AbstractSyslogMessageSender implemen
private Socket socket;
private Writer writer;
private int socketConnectTimeoutInMillis = SETTING_SOCKET_CONNECT_TIMEOUT_IN_MILLIS_DEFAULT_VALUE;
private int socketSoTimeout = SETTING_SOCKET_SO_TIMEOUT_IN_MILLIS_DEFAULT_VALUE;
private boolean ssl;
private SSLContext sslContext;
/**
Expand Down Expand Up @@ -154,6 +156,7 @@ private synchronized void ensureSyslogServerConnection() throws IOException {
} else {
socket = SocketFactory.getDefault().createSocket();
}
socket.setSoTimeout(socketSoTimeout);
socket.setKeepAlive(true);
socket.connect(
new InetSocketAddress(inetAddress, syslogServerPort),
Expand Down Expand Up @@ -245,6 +248,10 @@ public int getSocketConnectTimeoutInMillis() {
return socketConnectTimeoutInMillis;
}

public int getSocketSoTimeout() {
return socketSoTimeout;
}

public int getMaxRetryCount() {
return maxRetryCount;
}
Expand All @@ -257,6 +264,10 @@ public void setSocketConnectTimeoutInMillis(int socketConnectTimeoutInMillis) {
this.socketConnectTimeoutInMillis = socketConnectTimeoutInMillis;
}

public void setSocketSoTimeout(int socketSoTimeout) {
this.socketSoTimeout = socketSoTimeout;
}

public void setMaxRetryCount(int maxRetryCount) {
this.maxRetryCount = maxRetryCount;
}
Expand All @@ -273,6 +284,7 @@ public String toString() {
", ssl=" + ssl +
", maxRetryCount=" + maxRetryCount +
", socketConnectTimeoutInMillis=" + socketConnectTimeoutInMillis +
", socketSoTimeout=" + socketSoTimeout +
", defaultAppName='" + defaultAppName + '\'' +
", defaultFacility=" + defaultFacility +
", defaultMessageHostname='" + defaultMessageHostname + '\'' +
Expand Down
Loading