[Modify] Add it

This commit is contained in:
sta 2017-05-31 15:24:48 +09:00
parent 42c66ab65c
commit 963db4bdf0

View File

@ -775,6 +775,61 @@ namespace WebSocketSharp.Server
_receiveThread.Start ();
}
private void stop (ushort code, string reason)
{
if (_state == ServerState.Ready) {
_log.Info ("The server is not started.");
return;
}
if (_state == ServerState.ShuttingDown) {
_log.Info ("The server is shutting down.");
return;
}
if (_state == ServerState.Stop) {
_log.Info ("The server has already stopped.");
return;
}
lock (_sync) {
if (_state == ServerState.ShuttingDown) {
_log.Info ("The server is shutting down.");
return;
}
if (_state == ServerState.Stop) {
_log.Info ("The server has already stopped.");
return;
}
_state = ServerState.ShuttingDown;
}
try {
var threw = false;
try {
_services.Stop (code, reason);
}
catch {
threw = true;
throw;
}
finally {
try {
stopReceiving (5000);
}
catch {
if (!threw)
throw;
}
}
}
finally {
_state = ServerState.Stop;
}
}
private void stopReceiving (int millisecondsTimeout)
{
_listener.Close ();