Skip to content

Commit

Permalink
Add possibility to set keepAlive option (#750)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfod authored Jan 22, 2024
1 parent ed51655 commit e4ff1b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/main/java/software/amazon/awssdk/crt/io/SocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ int getValue() {
*/
public int keepAliveTimeoutSecs = 0;

/**
* If true, enables periodic transmits of keepalive messages for detecting a disconnected peer.
*/
public boolean keepAlive = false;

/**
* Creates a new set of socket options
*/
Expand All @@ -103,7 +108,8 @@ public long getNativeHandle() {
type.getValue(),
connectTimeoutMs,
keepAliveIntervalSecs,
keepAliveTimeoutSecs
keepAliveTimeoutSecs,
keepAlive
));
}
return super.getNativeHandle();
Expand All @@ -129,7 +135,7 @@ protected void releaseNativeHandle() {
/*******************************************************************************
* native methods
******************************************************************************/
private static native long socketOptionsNew(int domain, int type, int connectTimeoutMs, int keepAliveIntervalSecs, int keepAliveTimeoutSecs);
private static native long socketOptionsNew(int domain, int type, int connectTimeoutMs, int keepAliveIntervalSecs, int keepAliveTimeoutSecs, boolean keepAlive);

private static native void socketOptionsDestroy(long elg);
};
4 changes: 3 additions & 1 deletion src/native/socket_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jlong JNICALL Java_software_amazon_awssdk_crt_io_SocketOptions_socketOptionsNew(
jint type,
jint connect_timeout_ms,
jint keep_alive_interval_secs,
jint keep_alive_timeout_secs) {
jint keep_alive_timeout_secs,
jboolean keep_alive) {
(void)jni_class;
aws_cache_jni_ids(env);

Expand All @@ -44,6 +45,7 @@ jlong JNICALL Java_software_amazon_awssdk_crt_io_SocketOptions_socketOptionsNew(
options->connect_timeout_ms = connect_timeout_ms;
options->keep_alive_interval_sec = (short)keep_alive_interval_secs;
options->keep_alive_timeout_sec = (short)keep_alive_timeout_secs;
options->keepalive = keep_alive;

return (jlong)options;
}
Expand Down

0 comments on commit e4ff1b8

Please sign in to comment.