mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-18 11:40:46 +02:00
Use TcpClient.Connect().
This commit is contained in:
parent
0496e18179
commit
361f51ac94
|
@ -111,11 +111,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
|
|
||||||
public async Task<bool> CheckTunerAvailability(IPAddress remoteIp, int tuner, CancellationToken cancellationToken)
|
public async Task<bool> CheckTunerAvailability(IPAddress remoteIp, int tuner, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using (var client = new TcpClient(remoteIp.ToString(), HdHomeRunPort))
|
using var client = new TcpClient();
|
||||||
using (var stream = client.GetStream())
|
client.Connect(remoteIp, HdHomeRunPort);
|
||||||
{
|
|
||||||
return await CheckTunerAvailability(stream, tuner, cancellationToken).ConfigureAwait(false);
|
using var stream = client.GetStream();
|
||||||
}
|
return await CheckTunerAvailability(stream, tuner, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<bool> CheckTunerAvailability(NetworkStream stream, int tuner, CancellationToken cancellationToken)
|
private static async Task<bool> CheckTunerAvailability(NetworkStream stream, int tuner, CancellationToken cancellationToken)
|
||||||
|
@ -142,7 +142,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
{
|
{
|
||||||
_remoteEndPoint = new IPEndPoint(remoteIp, HdHomeRunPort);
|
_remoteEndPoint = new IPEndPoint(remoteIp, HdHomeRunPort);
|
||||||
|
|
||||||
_tcpClient = new TcpClient(_remoteEndPoint.Address.ToString(), _remoteEndPoint.Port);
|
_tcpClient = new TcpClient();
|
||||||
|
_tcpClient.Connect(_remoteEndPoint);
|
||||||
|
|
||||||
if (!_lockkey.HasValue)
|
if (!_lockkey.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -221,30 +222,30 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var tcpClient = new TcpClient(_remoteEndPoint.Address.ToString(), _remoteEndPoint.Port))
|
using var tcpClient = new TcpClient();
|
||||||
using (var stream = tcpClient.GetStream())
|
tcpClient.Connect(_remoteEndPoint);
|
||||||
{
|
|
||||||
var commandList = commands.GetCommands();
|
|
||||||
byte[] buffer = ArrayPool<byte>.Shared.Rent(8192);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
foreach (var command in commandList)
|
|
||||||
{
|
|
||||||
var channelMsg = CreateSetMessage(_activeTuner, command.Item1, command.Item2, _lockkey);
|
|
||||||
await stream.WriteAsync(channelMsg, 0, channelMsg.Length, cancellationToken).ConfigureAwait(false);
|
|
||||||
int receivedBytes = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
// parse response to make sure it worked
|
using var stream = tcpClient.GetStream();
|
||||||
if (!ParseReturnMessage(buffer, receivedBytes, out _))
|
var commandList = commands.GetCommands();
|
||||||
{
|
byte[] buffer = ArrayPool<byte>.Shared.Rent(8192);
|
||||||
return;
|
try
|
||||||
}
|
{
|
||||||
|
foreach (var command in commandList)
|
||||||
|
{
|
||||||
|
var channelMsg = CreateSetMessage(_activeTuner, command.Item1, command.Item2, _lockkey);
|
||||||
|
await stream.WriteAsync(channelMsg, 0, channelMsg.Length, cancellationToken).ConfigureAwait(false);
|
||||||
|
int receivedBytes = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// parse response to make sure it worked
|
||||||
|
if (!ParseReturnMessage(buffer, receivedBytes, out _))
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
}
|
||||||
{
|
finally
|
||||||
ArrayPool<byte>.Shared.Return(buffer);
|
{
|
||||||
}
|
ArrayPool<byte>.Shared.Return(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue