Added the WebSocket.CheckPingParameter method, and removed the Ext.CheckIfValidControlData method

This commit is contained in:
sta 2015-05-05 15:21:28 +09:00
parent 531eefac17
commit dee36926ae
4 changed files with 12 additions and 17 deletions

View File

@ -251,13 +251,6 @@ namespace WebSocketSharp
: null;
}
internal static string CheckIfValidControlData (this byte[] data, string paramName)
{
return data.Length > 125
? String.Format ("'{0}' has greater than the allowable max size.", paramName)
: null;
}
internal static string CheckIfValidProtocols (this string[] protocols)
{
return protocols.Contains (

View File

@ -566,10 +566,8 @@ namespace WebSocketSharp.Server
if (message == null || message.Length == 0)
return Broadping ();
byte[] data = null;
var msg = _state.CheckIfStart () ??
(data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message");
byte[] data;
var msg = _state.CheckIfStart () ?? WebSocket.CheckPingParameter (message, out data);
if (msg != null) {
_logger.Error (msg);
return null;

View File

@ -571,10 +571,8 @@ namespace WebSocketSharp.Server
if (message == null || message.Length == 0)
return Broadping ();
byte[] data = null;
var msg = _state.CheckIfStart () ??
(data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message");
byte[] data;
var msg = _state.CheckIfStart () ?? WebSocket.CheckPingParameter (message, out data);
if (msg != null) {
_logger.Error (msg);
return null;

View File

@ -1588,6 +1588,12 @@ namespace WebSocketSharp
: null;
}
internal static string CheckPingParameter (string message, out byte[] bytes)
{
bytes = Encoding.UTF8.GetBytes (message);
return bytes.Length > 125 ? "A message has greater than the allowable max size." : null;
}
// As server
internal void Close (HttpResponse response)
{
@ -2114,8 +2120,8 @@ namespace WebSocketSharp
if (message == null || message.Length == 0)
return Ping ();
var data = Encoding.UTF8.GetBytes (message);
var msg = data.CheckIfValidControlData ("message");
byte[] data;
var msg = CheckPingParameter (message, out data);
if (msg != null) {
_logger.Error (msg);
error ("An error has occurred in sending the ping.", null);