Added the internal Ext.CheckIfCanStop (ServerState) method

This commit is contained in:
sta 2015-08-13 11:41:38 +09:00
parent 46eae139e2
commit 80a0107bab
3 changed files with 13 additions and 6 deletions

View File

@ -245,6 +245,13 @@ namespace WebSocketSharp
: null;
}
internal static string CheckIfCanStop (this ServerState state)
{
return state != ServerState.Start
? String.Format ("This operation isn't available ({0}).", state)
: null;
}
internal static string CheckIfStart (this ServerState state)
{
return state == ServerState.Ready

View File

@ -911,7 +911,7 @@ namespace WebSocketSharp.Server
public void Stop ()
{
lock (_sync) {
var msg = _state.CheckIfStart ();
var msg = _state.CheckIfCanStop ();
if (msg != null) {
_logger.Error (msg);
return;
@ -939,7 +939,7 @@ namespace WebSocketSharp.Server
public void Stop (ushort code, string reason)
{
lock (_sync) {
var msg = _state.CheckIfStart () ?? WebSocket.CheckCloseParameters (code, reason, false);
var msg = _state.CheckIfCanStop () ?? WebSocket.CheckCloseParameters (code, reason, false);
if (msg != null) {
_logger.Error (msg);
return;
@ -975,7 +975,7 @@ namespace WebSocketSharp.Server
public void Stop (CloseStatusCode code, string reason)
{
lock (_sync) {
var msg = _state.CheckIfStart () ?? WebSocket.CheckCloseParameters (code, reason, false);
var msg = _state.CheckIfCanStop () ?? WebSocket.CheckCloseParameters (code, reason, false);
if (msg != null) {
_logger.Error (msg);
return;

View File

@ -814,7 +814,7 @@ namespace WebSocketSharp.Server
public void Stop ()
{
lock (_sync) {
var msg = _state.CheckIfStart ();
var msg = _state.CheckIfCanStop ();
if (msg != null) {
_logger.Error (msg);
return;
@ -842,7 +842,7 @@ namespace WebSocketSharp.Server
public void Stop (ushort code, string reason)
{
lock (_sync) {
var msg = _state.CheckIfStart () ?? WebSocket.CheckCloseParameters (code, reason, false);
var msg = _state.CheckIfCanStop () ?? WebSocket.CheckCloseParameters (code, reason, false);
if (msg != null) {
_logger.Error (msg);
return;
@ -877,7 +877,7 @@ namespace WebSocketSharp.Server
public void Stop (CloseStatusCode code, string reason)
{
lock (_sync) {
var msg = _state.CheckIfStart () ?? WebSocket.CheckCloseParameters (code, reason, false);
var msg = _state.CheckIfCanStop () ?? WebSocket.CheckCloseParameters (code, reason, false);
if (msg != null) {
_logger.Error (msg);
return;