Skip to content

Commit

Permalink
Make connection timeout configurable (defaults to 10 seconds) (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Apr 11, 2021
1 parent 20d8fc1 commit 541f3e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/src/main/java/xyz/gianlu/librespot/core/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,14 @@ public final static class Configuration {
// Fetching
public final boolean retryOnChunkError;

// Network
public final int connectionTimeout;

private Configuration(boolean proxyEnabled, Proxy.Type proxyType, String proxyAddress, int proxyPort, boolean proxyAuth, String proxyUsername, String proxyPassword,
TimeProvider.Method timeSynchronizationMethod, int timeManualCorrection,
boolean cacheEnabled, File cacheDir, boolean doCacheCleanUp,
boolean storeCredentials, File storedCredentialsFile,
boolean retryOnChunkError) {
boolean retryOnChunkError, int connectionTimeout) {
this.proxyEnabled = proxyEnabled;
this.proxyType = proxyType;
this.proxyAddress = proxyAddress;
Expand All @@ -1043,6 +1046,7 @@ private Configuration(boolean proxyEnabled, Proxy.Type proxyType, String proxyAd
this.storeCredentials = storeCredentials;
this.storedCredentialsFile = storedCredentialsFile;
this.retryOnChunkError = retryOnChunkError;
this.connectionTimeout = connectionTimeout;
}

public static final class Builder {
Expand Down Expand Up @@ -1071,6 +1075,9 @@ public static final class Builder {
// Fetching
private boolean retryOnChunkError;

// Network
private int connectionTimeout;

public Builder() {
}

Expand Down Expand Up @@ -1149,13 +1156,18 @@ public Builder setRetryOnChunkError(boolean retryOnChunkError) {
return this;
}

public Builder setConnectionTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
return this;
}

@NotNull
public Configuration build() {
return new Configuration(proxyEnabled, proxyType, proxyAddress, proxyPort, proxyAuth, proxyUsername, proxyPassword,
timeSynchronizationMethod, timeManualCorrection,
cacheEnabled, cacheDir, doCacheCleanUp,
storeCredentials, storedCredentialsFile,
retryOnChunkError);
retryOnChunkError, connectionTimeout);
}
}
}
Expand Down Expand Up @@ -1298,7 +1310,7 @@ public void run() {
scheduledReconnect = scheduler.schedule(() -> {
LOGGER.warn("Socket timed out. Reconnecting...");
reconnect();
}, 2 * 60 + 5, TimeUnit.SECONDS);
}, 2 * 60 + configuration().connectionTimeout, TimeUnit.SECONDS);

TimeProvider.updateWithPing(packet.payload);

Expand Down
3 changes: 3 additions & 0 deletions player/src/main/resources/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ enabled = true # Cache enabled
dir = "./cache/"
doCleanUp = true

[network] ### Network ###
connectionTimeout = 10 # If ping isn't received within this amount of seconds, reconnect

[preload] ### Preload ###
enabled = true # Preload enabled

Expand Down

0 comments on commit 541f3e7

Please sign in to comment.