Modified Ping

This commit is contained in:
sta 2014-01-30 17:13:03 +09:00
parent 68ab8e9ea9
commit 81993cbd97
5 changed files with 15 additions and 47 deletions

View File

@ -251,10 +251,11 @@ namespace WebSocketSharp
: null; : null;
} }
internal static string CheckIfValidPingData (this byte [] data) internal static string CheckIfValidControlData (
this byte [] data, string paramName)
{ {
return data.Length > 125 return data.Length > 125
? "'message' length must be less." ? String.Format ("'{0}' length must be less.", paramName)
: null; : null;
} }

View File

@ -269,39 +269,6 @@ namespace WebSocketSharp.Server
{ {
} }
/// <summary>
/// Sends a Ping to the client of the current <see cref="WebSocketService"/>
/// instance.
/// </summary>
/// <returns>
/// <c>true</c> if the current <see cref="WebSocketService"/> instance
/// receives a Pong from the client in a time; otherwise, <c>false</c>.
/// </returns>
protected bool Ping ()
{
return _websocket != null
? _websocket.Ping ()
: false;
}
/// <summary>
/// Sends a Ping with the specified <paramref name="message"/> to the client
/// of the current <see cref="WebSocketService"/> instance.
/// </summary>
/// <returns>
/// <c>true</c> if the current <see cref="WebSocketService"/> instance
/// receives a Pong from the client in a time; otherwise, <c>false</c>.
/// </returns>
/// <param name="message">
/// A <see cref="string"/> that represents the message to send.
/// </param>
protected bool Ping (string message)
{
return _websocket != null
? _websocket.Ping (message)
: false;
}
/// <summary> /// <summary>
/// Sends a binary <paramref name="data"/> to the client of the current /// Sends a binary <paramref name="data"/> to the client of the current
/// <see cref="WebSocketService"/> instance. /// <see cref="WebSocketService"/> instance.

View File

@ -672,7 +672,7 @@ namespace WebSocketSharp.Server
byte [] data = null; byte [] data = null;
var msg = _state.CheckIfStarted () ?? var msg = _state.CheckIfStarted () ??
(data = Encoding.UTF8.GetBytes (message)).CheckIfValidPingData (); (data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message");
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);

View File

@ -588,7 +588,7 @@ namespace WebSocketSharp.Server
byte [] data = null; byte [] data = null;
var msg = _state.CheckIfStarted () ?? var msg = _state.CheckIfStarted () ??
(data = Encoding.UTF8.GetBytes (message)).CheckIfValidPingData (); (data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message");
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);

View File

@ -1437,10 +1437,9 @@ namespace WebSocketSharp
return Convert.ToBase64String (src); return Convert.ToBase64String (src);
} }
internal bool Ping (byte [] frameAsBytes, int timeOut) internal bool Ping (byte [] frame, int millisecondsTimeout)
{ {
return send (frameAsBytes) && return send (frame) && _receivePong.WaitOne (millisecondsTimeout);
_receivePong.WaitOne (timeOut);
} }
// As server, used to broadcast // As server, used to broadcast
@ -1806,8 +1805,8 @@ namespace WebSocketSharp
/// Sends a Ping using the WebSocket connection. /// Sends a Ping using the WebSocket connection.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// <c>true</c> if the <see cref="WebSocket"/> instance receives a Pong in a time; /// <c>true</c> if the <see cref="WebSocket"/> instance receives the Pong to
/// otherwise, <c>false</c>. /// this Ping from the server in a time; otherwise, <c>false</c>.
/// </returns> /// </returns>
public bool Ping () public bool Ping ()
{ {
@ -1817,14 +1816,15 @@ namespace WebSocketSharp
} }
/// <summary> /// <summary>
/// Sends a Ping with the specified <paramref name="message"/> using the WebSocket connection. /// Sends a Ping with the specified <paramref name="message"/> using the
/// WebSocket connection.
/// </summary> /// </summary>
/// <param name="message"> /// <param name="message">
/// A <see cref="string"/> that contains a message to send. /// A <see cref="string"/> that represents the message to send.
/// </param> /// </param>
/// <returns> /// <returns>
/// <c>true</c> if the <see cref="WebSocket"/> instance receives a Pong in a time; /// <c>true</c> if the <see cref="WebSocket"/> instance receives the Pong to
/// otherwise, <c>false</c>. /// this Ping from the server in a time; otherwise, <c>false</c>.
/// </returns> /// </returns>
public bool Ping (string message) public bool Ping (string message)
{ {
@ -1832,7 +1832,7 @@ namespace WebSocketSharp
return Ping (); return Ping ();
var data = Encoding.UTF8.GetBytes (message); var data = Encoding.UTF8.GetBytes (message);
var msg = data.CheckIfValidPingData (); var msg = data.CheckIfValidControlData ("message");
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);
error (msg); error (msg);