|
@@ -101,44 +101,49 @@ namespace DotnetRtmpServer.Net
|
|
|
IsClosed = true;
|
|
|
await OnClosedAsync().ConfigureAwait(false);
|
|
|
DoDispose();
|
|
|
- Logger.WriteLineInfo($"[{ConnectionType}] Connection closed, ConnectionId={Id}");
|
|
|
+ Logger.WriteLineInfo($"[{ConnectionType}] Connection {Id} closed.");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void StartProcess()
|
|
|
+ public void StartIoProcess()
|
|
|
{
|
|
|
- Task.Run(DoProcessAsync);
|
|
|
+ Task.Run(DoStartIoProcessAsync);
|
|
|
}
|
|
|
|
|
|
|
|
|
- private async void DoProcessAsync()
|
|
|
+ public async Task ProcessOnceAsync()
|
|
|
{
|
|
|
- while (!IsClosed)
|
|
|
+ try
|
|
|
{
|
|
|
- try
|
|
|
+ var hw = await WriteAsync().ConfigureAwait(false);
|
|
|
+ var hr = await ReadAsync().ConfigureAwait(false);
|
|
|
+ if (hw || hr)
|
|
|
{
|
|
|
- var hw = await WriteAsync().ConfigureAwait(false);
|
|
|
- var hr = await ReadAsync().ConfigureAwait(false);
|
|
|
- if (hw || hr)
|
|
|
- {
|
|
|
- LastPing = DateTime.UtcNow;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (DateTime.UtcNow - LastPing > IoTimeout)
|
|
|
- {
|
|
|
- await CloseAsync().ConfigureAwait(false);
|
|
|
- Logger.WriteLineWarn($"[{ConnectionType}]Connection closed because it has no writing or reading over {IoTimeout.Seconds} seconds.");
|
|
|
- }
|
|
|
- }
|
|
|
+ LastPing = DateTime.UtcNow;
|
|
|
}
|
|
|
- catch
|
|
|
+ else
|
|
|
{
|
|
|
- await CloseAsync().ConfigureAwait(false);
|
|
|
- Logger.WriteLineWarn($"Connection {Id} closed.");
|
|
|
+ if (DateTime.UtcNow - LastPing > IoTimeout)
|
|
|
+ {
|
|
|
+ await CloseAsync().ConfigureAwait(false);
|
|
|
+ Logger.WriteLineWarn($"[{ConnectionType}]Connection closed because it has no writing or reading over {IoTimeout.Seconds} seconds.");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ await CloseAsync().ConfigureAwait(false);
|
|
|
+ Logger.WriteLineWarn($"Connection {Id} closed.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void DoStartIoProcessAsync()
|
|
|
+ {
|
|
|
+ while (!IsClosed)
|
|
|
+ {
|
|
|
+ await ProcessOnceAsync().ConfigureAwait(false);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|