Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've added support for passing CancellationTokens into RconSharp.
Rationale
The main reason why I decided to do this, is because my Minecraft server shuts down automatically when nobody is online for 20 minutes, and starts automatically when some tries to join. The web app I wrote for managing the server doesn't play nice with this system, as the RconClient is used as a singleton within the app. If I try to execute a command after the server has shut down, even if the server has already started again, a reply never arrives because the server does not have an open connection with my app, even though RconSharp thinks it has an open connection with the server.So I did this so you can specify a timeout for ExecuteCommandAsync and ConnectAsync. However, there is a weird problem with the compiler. If I try to compile this right now, there is an error in SocketChannel.cs, line 81, where the compiler can't see the extension method
ConnectAsync(string, int, CancellationToken)
even though it clearly exists within the same class as the ConnectAsync that was previously used. After some investigation, I found out that there are two distinct CancellationTokens: one defined in System.Runtime.dll, and the other in System.Private.CoreLib.dll. The first one is used by RconSharp, and the second one is used by SocketChannelExtensions. I'm not sure why this is a problem for ConnectAsync, becauseSendAsync
andReceiveAsync
do not have this problem.Directly calling the extension method as
System.Net.Sockets.SocketTaskExtensions.ConnectAsync(socket, host, port, cancellationToken)
does not work either.I was wondering if you had any idea how to fix this.
(These changes were not tested because of this issue.)