From 98ea758c1ff05831d79088a52c43c7ecec7aa4a1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 26 Nov 2021 15:40:03 -0600 Subject: add ConnectionOptions.With extension --- src/slskd/Common/Extensions.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/slskd/Common') diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 4d463092..32a9b26e 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -21,10 +21,12 @@ namespace slskd using System.Collections.Generic; using System.IO; using System.Linq; + using System.Net.Sockets; using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.RegularExpressions; + using Soulseek; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; @@ -282,6 +284,36 @@ namespace slskd return Path.Combine(path, sanitizedFilename).TrimStart('\\').TrimStart('/'); } + /// + /// Creates a copy of this instance with the specified parameters changed. + /// + /// The options instance to copy. + /// The read buffer size for underlying TCP connections. + /// The write buffer size for underlying TCP connections. + /// The size of the write queue for double buffered writes. + /// The connection timeout, in milliseconds, for client and peer TCP connections. + /// The inactivity timeout, in milliseconds, for peer TCP connections. + /// Optional SOCKS 5 proxy configuration options. + /// + /// The delegate invoked during instantiation to configure the server Socket instance. + /// + /// The new instance. + public static ConnectionOptions With( + this ConnectionOptions o, + int? readBufferSize = null, + int? writeBufferSize = null, + int? writeQueueSize = null, + int? connectTimeout = null, + int? inactivityTimeout = null, + ProxyOptions proxyOptions = null, + Action configureSocketAction = null) => new ConnectionOptions( + readBufferSize: readBufferSize ?? o.ReadBufferSize, + writeBufferSize: writeBufferSize ?? o.WriteBufferSize, + writeQueueSize: writeQueueSize ?? o.WriteQueueSize, + connectTimeout: connectTimeout ?? o.ConnectTimeout, + inactivityTimeout: inactivityTimeout ?? o.InactivityTimeout, + configureSocketAction: configureSocketAction ?? o.ConfigureSocketAction); + /// /// Deserializes this string from json to an object of type . /// -- cgit v1.2.3