From ce20066bc0e2c7ba1634200cdee6ac339d4dfb60 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Jul 2014 00:46:29 -0400 Subject: update translations --- .../HttpServer/HttpListenerHost.cs | 2 +- .../HttpServer/NativeWebSocket.cs | 21 +++++++++++++++++-- .../HttpServer/SocketSharp/SharpWebSocket.cs | 24 ++++++++++++++-------- 3 files changed, 36 insertions(+), 11 deletions(-) (limited to 'MediaBrowser.Server.Implementations/HttpServer') diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 62a43751d..f530564ea 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -157,7 +157,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer HostContext.Config.HandlerFactoryPath = ListenerRequest.GetHandlerPathIfAny(UrlPrefixes.First()); _listener = NativeWebSocket.IsSupported - ? _listener = new HttpListenerServer(_logger, _threadPoolManager) + ? _listener = new WebSocketSharpListener(_logger, _threadPoolManager) : _listener = new WebSocketSharpListener(_logger, _threadPoolManager); _listener.WebSocketHandler = WebSocketHandler; diff --git a/MediaBrowser.Server.Implementations/HttpServer/NativeWebSocket.cs b/MediaBrowser.Server.Implementations/HttpServer/NativeWebSocket.cs index f89cdac47..c7669fecb 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/NativeWebSocket.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/NativeWebSocket.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Events; +using System.Text; +using MediaBrowser.Common.Events; using MediaBrowser.Common.Net; using MediaBrowser.Model.Logging; using System; @@ -36,7 +37,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// The socket. /// The logger. /// socket - public NativeWebSocket(System.Net.WebSockets.WebSocket socket, ILogger logger) + public NativeWebSocket(WebSocket socket, ILogger logger) { if (socket == null) { @@ -155,6 +156,22 @@ namespace MediaBrowser.Server.Implementations.HttpServer return WebSocket.SendAsync(new ArraySegment(bytes), nativeType, true, linkedTokenSource.Token); } + public Task SendAsync(byte[] bytes, bool endOfMessage, CancellationToken cancellationToken) + { + var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _cancellationTokenSource.Token); + + return WebSocket.SendAsync(new ArraySegment(bytes), System.Net.WebSockets.WebSocketMessageType.Binary, true, linkedTokenSource.Token); + } + + public Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken) + { + var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _cancellationTokenSource.Token); + + var bytes = Encoding.UTF8.GetBytes(text); + + return WebSocket.SendAsync(new ArraySegment(bytes), System.Net.WebSockets.WebSocketMessageType.Text, true, linkedTokenSource.Token); + } + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// diff --git a/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/SharpWebSocket.cs b/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/SharpWebSocket.cs index 412789240..7ff3a1247 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/SharpWebSocket.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/SharpWebSocket.cs @@ -96,22 +96,30 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp /// Sends the async. /// /// The bytes. - /// The type. /// if set to true [end of message]. /// The cancellation token. /// Task. - public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) + public Task SendAsync(byte[] bytes, bool endOfMessage, CancellationToken cancellationToken) { - System.Net.WebSockets.WebSocketMessageType nativeType; + var completionSource = new TaskCompletionSource(); - if (!Enum.TryParse(type.ToString(), true, out nativeType)) - { - _logger.Warn("Unrecognized WebSocketMessageType: {0}", type.ToString()); - } + WebSocket.SendAsync(bytes, res => completionSource.TrySetResult(true)); + + return completionSource.Task; + } + /// + /// Sends the asynchronous. + /// + /// The text. + /// if set to true [end of message]. + /// The cancellation token. + /// Task. + public Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken) + { var completionSource = new TaskCompletionSource(); - WebSocket.SendAsync(Encoding.UTF8.GetString(bytes), res => completionSource.TrySetResult(true)); + WebSocket.SendAsync(text, res => completionSource.TrySetResult(true)); return completionSource.Task; } -- cgit v1.2.3