From ddb5819a0eb3d978cd7bdd7bb7b483e76aef1e9e Mon Sep 17 00:00:00 2001 From: sta Date: Fri, 21 Aug 2015 16:31:50 +0900 Subject: [PATCH] Added the WebSocket.CheckSendParameters method --- websocket-sharp/Ext.cs | 9 --------- websocket-sharp/Server/WebSocketServiceManager.cs | 3 +-- websocket-sharp/Server/WebSocketSessionManager.cs | 3 +-- websocket-sharp/WebSocket.cs | 14 ++++++++++++-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 634538e5..a45fda84 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -222,15 +222,6 @@ namespace WebSocketSharp : null; } - internal static string CheckIfCanRead (this Stream stream) - { - return stream == null - ? "'stream' is null." - : !stream.CanRead - ? "'stream' cannot be read." - : null; - } - internal static string CheckIfValidProtocols (this string[] protocols) { return protocols.Contains ( diff --git a/websocket-sharp/Server/WebSocketServiceManager.cs b/websocket-sharp/Server/WebSocketServiceManager.cs index bd1269d9..3f224003 100644 --- a/websocket-sharp/Server/WebSocketServiceManager.cs +++ b/websocket-sharp/Server/WebSocketServiceManager.cs @@ -503,8 +503,7 @@ namespace WebSocketSharp.Server public void BroadcastAsync (Stream stream, int length, Action completed) { var msg = _state.CheckIfAvailable (false, true, false) ?? - stream.CheckIfCanRead () ?? - (length < 1 ? "'length' is less than 1." : null); + WebSocket.CheckSendParameters (stream, length); if (msg != null) { _logger.Error (msg); diff --git a/websocket-sharp/Server/WebSocketSessionManager.cs b/websocket-sharp/Server/WebSocketSessionManager.cs index de472925..96fd6235 100644 --- a/websocket-sharp/Server/WebSocketSessionManager.cs +++ b/websocket-sharp/Server/WebSocketSessionManager.cs @@ -511,8 +511,7 @@ namespace WebSocketSharp.Server public void BroadcastAsync (Stream stream, int length, Action completed) { var msg = _state.CheckIfAvailable (false, true, false) ?? - stream.CheckIfCanRead () ?? - (length < 1 ? "'length' is less than 1." : null); + WebSocket.CheckSendParameters (stream, length); if (msg != null) { _logger.Error (msg); diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 77fcc7fd..e6f1b3a0 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -1640,6 +1640,17 @@ namespace WebSocketSharp return data == null ? "'data' is null." : null; } + internal static string CheckSendParameters (Stream stream, int length) + { + return stream == null + ? "'stream' is null." + : !stream.CanRead + ? "'stream' cannot be read." + : length < 1 + ? "'length' is less than 1." + : null; + } + // As server internal void Close (HttpResponse response) { @@ -2427,8 +2438,7 @@ namespace WebSocketSharp public void SendAsync (Stream stream, int length, Action completed) { var msg = _readyState.CheckIfAvailable (false, true, false, false) ?? - stream.CheckIfCanRead () ?? - (length < 1 ? "'length' is less than 1." : null); + CheckSendParameters (stream, length); if (msg != null) { _logger.Error (msg);