|
4 | 4 | using System.IO; |
5 | 5 | using System.Linq; |
6 | 6 | using System.Net.Sockets; |
| 7 | +using System.Runtime.CompilerServices; |
7 | 8 | using System.Threading; |
8 | 9 | using System.Threading.Tasks; |
9 | 10 | using TS3QueryLib.Core.Common; |
@@ -146,8 +147,14 @@ public async Task<string> SendAsync(string messageToSend) |
146 | 147 |
|
147 | 148 | protected static async Task SendAsync(StreamWriter writer, string messageToSend) |
148 | 149 | { |
149 | | - await writer.WriteLineAsync(messageToSend).ConfigureAwait(false); |
150 | | - await writer.FlushAsync().ConfigureAwait(false); |
| 150 | + ConfiguredTaskAwaitable? writeLineAwaitable = writer?.WriteLineAsync(messageToSend).ConfigureAwait(false); |
| 151 | + |
| 152 | + if (writeLineAwaitable.HasValue) |
| 153 | + await writeLineAwaitable.Value; |
| 154 | + |
| 155 | + ConfiguredTaskAwaitable? flushAwaitable = writer?.FlushAsync().ConfigureAwait(false); |
| 156 | + if (flushAwaitable.HasValue) |
| 157 | + await flushAwaitable.Value; |
151 | 158 | } |
152 | 159 |
|
153 | 160 | public void Disconnect() |
@@ -197,7 +204,7 @@ protected async void ReadLoop() |
197 | 204 | ReceivedLines.Clear(); |
198 | 205 | } |
199 | 206 |
|
200 | | - string responseText = string.Join("\r\n", ReceivedLines.Concat(new[] { message })); |
| 207 | + string responseText = string.Join("\n\r", ReceivedLines.Concat(new[] { message })); |
201 | 208 | MessageResponses.Enqueue(responseText); |
202 | 209 | ReceivedLines.Clear(); |
203 | 210 |
|
@@ -231,7 +238,8 @@ protected async void ReadLoop() |
231 | 238 |
|
232 | 239 | protected async Task<string> ReadLineAsync(bool throwOnEmptyMessage = true) |
233 | 240 | { |
234 | | - string message = await ClientReader.ReadLineAsync().ConfigureAwait(false); |
| 241 | + ConfiguredTaskAwaitable<string>? readLineAwaitable = ClientReader?.ReadLineAsync().ConfigureAwait(false); |
| 242 | + string message = readLineAwaitable.HasValue ? await readLineAwaitable.Value : null; |
235 | 243 |
|
236 | 244 | if (message != null) |
237 | 245 | return message; |
|
0 commit comments