mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 18:08:53 -07:00
update http server
This commit is contained in:
parent
9f3891d418
commit
35f40993b2
@ -12,8 +12,6 @@ namespace MediaBrowser.Dlna.Profiles
|
||||
Name = "Xbox One";
|
||||
|
||||
TimelineOffsetSeconds = 40;
|
||||
RequiresPlainFolders = true;
|
||||
RequiresPlainVideoItems = true;
|
||||
|
||||
Identification = new DeviceIdentification
|
||||
{
|
||||
|
@ -205,8 +205,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
HostContext.Config.HandlerFactoryPath = ListenerRequest.GetHandlerPathIfAny(UrlPrefixes.First());
|
||||
|
||||
_listener = _supportsNativeWebSocket && NativeWebSocket.IsSupported
|
||||
? _listener = new HttpListenerServer(_logger, OnRequestReceived)
|
||||
//? _listener = new WebSocketSharpListener(_logger, OnRequestReceived)
|
||||
//? _listener = new HttpListenerServer(_logger, OnRequestReceived)
|
||||
? _listener = new WebSocketSharpListener(_logger, OnRequestReceived)
|
||||
: _listener = new WebSocketSharpListener(_logger, OnRequestReceived);
|
||||
|
||||
_listener.WebSocketHandler = WebSocketHandler;
|
||||
|
@ -173,9 +173,64 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
ThrottleCallback = ThrottleCallback
|
||||
};
|
||||
}
|
||||
var task = WriteToAsync(responseStream);
|
||||
WriteToInternal(responseStream);
|
||||
}
|
||||
|
||||
Task.WaitAll(task);
|
||||
/// <summary>
|
||||
/// Writes to async.
|
||||
/// </summary>
|
||||
/// <param name="responseStream">The response stream.</param>
|
||||
/// <returns>Task.</returns>
|
||||
private void WriteToInternal(Stream responseStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Headers only
|
||||
if (IsHeadRequest)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var source = SourceStream)
|
||||
{
|
||||
// If the requested range is "0-", we can optimize by just doing a stream copy
|
||||
if (RangeEnd >= TotalContentLength - 1)
|
||||
{
|
||||
source.CopyTo(responseStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyToInternal(source, responseStream, Convert.ToInt32(RangeLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (OnComplete != null)
|
||||
{
|
||||
OnComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyToInternal(Stream source, Stream destination, int copyLength)
|
||||
{
|
||||
const int bufferSize = 81920;
|
||||
var array = new byte[bufferSize];
|
||||
int count;
|
||||
while ((count = source.Read(array, 0, array.Length)) != 0)
|
||||
{
|
||||
var bytesToCopy = Math.Min(count, copyLength);
|
||||
|
||||
destination.Write(array, 0, bytesToCopy);
|
||||
|
||||
copyLength -= bytesToCopy;
|
||||
|
||||
if (copyLength <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -91,9 +91,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
ThrottleCallback = ThrottleCallback
|
||||
};
|
||||
}
|
||||
var task = WriteToAsync(responseStream);
|
||||
|
||||
Task.WaitAll(task);
|
||||
WriteToAsync(responseStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -101,13 +99,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||
/// </summary>
|
||||
/// <param name="responseStream">The response stream.</param>
|
||||
/// <returns>Task.</returns>
|
||||
private async Task WriteToAsync(Stream responseStream)
|
||||
private void WriteToAsync(Stream responseStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var src = SourceStream)
|
||||
{
|
||||
await src.CopyToAsync(responseStream).ConfigureAwait(false);
|
||||
src.CopyTo(responseStream);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user