Modified closing

This commit is contained in:
sta 2013-09-05 21:58:57 +09:00
parent e0a7e74d0a
commit b7313955c9
8 changed files with 36 additions and 32 deletions

View File

@ -462,9 +462,9 @@ namespace WebSocketSharp.Server
return;
}
_serviceHosts.Stop (data);
_listener.Close ();
_receiveRequestThread.Join (5 * 1000);
_serviceHosts.Stop (code, reason);
_listening = false;
}
@ -579,9 +579,9 @@ namespace WebSocketSharp.Server
if (!_listening)
return;
_serviceHosts.Stop ();
_listener.Close ();
_receiveRequestThread.Join (5 * 1000);
_serviceHosts.Stop ();
_listening = false;
}

View File

@ -201,14 +201,11 @@ namespace WebSocketSharp.Server
void Stop ();
/// <summary>
/// Stops the WebSocket service host with the specified <see cref="ushort"/> and <see cref="string"/>.
/// Stops the WebSocket service host with the specified array of <see cref="byte"/>.
/// </summary>
/// <param name="code">
/// A <see cref="ushort"/> that contains a status code indicating the reason for stop.
/// <param name="data">
/// An array of <see cref="byte"/> that contains the reason for stop.
/// </param>
/// <param name="reason">
/// A <see cref="string"/> that contains the reason for stop.
/// </param>
void Stop (ushort code, string reason);
void Stop (byte [] data);
}
}

View File

@ -207,7 +207,7 @@ namespace WebSocketSharp.Server
}
base.Stop ();
_serviceHosts.Stop (code, reason);
_serviceHosts.Stop (data);
}
#endregion

View File

@ -211,6 +211,11 @@ namespace WebSocketSharp.Server
_websocket.SendAsync (data, completed);
}
internal void Stop (byte [] data)
{
_websocket.Close (data);
}
#endregion
#region Protected Methods

View File

@ -280,7 +280,7 @@ namespace WebSocketSharp.Server
}
base.Stop ();
_sessions.Stop (code, reason);
_sessions.Stop (data);
}
#endregion
@ -765,19 +765,15 @@ namespace WebSocketSharp.Server
}
/// <summary>
/// Stops receiving the WebSocket connection requests with the specified <see cref="ushort"/> and
/// <see cref="string"/>.
/// Stops the WebSocket service host with the specified array of <see cref="byte"/>.
/// </summary>
/// <param name="code">
/// A <see cref="ushort"/> that contains a status code indicating the reason for stop.
/// <param name="data">
/// An array of <see cref="byte"/> that contains the reason for stop.
/// </param>
/// <param name="reason">
/// A <see cref="string"/> that contains the reason for stop.
/// </param>
void IWebSocketServiceHost.Stop (ushort code, string reason)
void IWebSocketServiceHost.Stop (byte [] data)
{
base.Stop ();
_sessions.Stop (code, reason);
_sessions.Stop (data);
}
#endregion

View File

@ -193,7 +193,7 @@ namespace WebSocketSharp.Server
_serviceHosts.Remove (servicePath);
}
host.Stop ((ushort) CloseStatusCode.AWAY, String.Empty);
host.Stop (((ushort) CloseStatusCode.AWAY).ToByteArray (ByteOrder.BIG));
return true;
}
@ -208,12 +208,12 @@ namespace WebSocketSharp.Server
}
}
internal void Stop (ushort code, string reason)
internal void Stop (byte [] data)
{
lock (_sync)
{
foreach (var host in _serviceHosts.Values)
host.Stop (code, reason);
host.Stop (data);
_serviceHosts.Clear ();
}

View File

@ -508,7 +508,7 @@ namespace WebSocketSharp.Server
}
}
internal void Stop (ushort code, string reason)
internal void Stop (byte [] data)
{
stopSweepTimer ();
lock (_sync)
@ -518,7 +518,7 @@ namespace WebSocketSharp.Server
_stopped = true;
foreach (var service in copy ().Values)
service.Stop (code, reason);
service.Stop (data);
}
}
@ -588,7 +588,7 @@ namespace WebSocketSharp.Server
{
var state = service.WebSocket.ReadyState;
if (state == WebSocketState.OPEN)
service.Stop (CloseStatusCode.ABNORMAL, String.Empty);
service.Stop (((ushort) CloseStatusCode.ABNORMAL).ToByteArray (ByteOrder.BIG));
else if (state == WebSocketState.CLOSING)
continue;
else

View File

@ -586,9 +586,9 @@ namespace WebSocketSharp
private void close (ushort code, string reason)
{
var data = code.Append (reason);
if (data.Length > 125)
var msg = data.CheckIfValidCloseData ();
if (msg != null)
{
var msg = "The payload length of a Close frame must be 125 bytes or less.";
_logger.Error (String.Format ("{0}\ncode: {1}\nreason: {2}", msg, code, reason));
error (msg);
@ -1314,6 +1314,12 @@ namespace WebSocketSharp
#region Internal Methods
// As server
internal void Close (byte [] data)
{
close (new PayloadData (data));
}
// As server
internal void Close (HttpStatusCode code)
{
@ -1346,7 +1352,7 @@ namespace WebSocketSharp
/// </param>
public void Close (ushort code)
{
Close (code, String.Empty);
Close (code, "");
}
/// <summary>
@ -1358,7 +1364,7 @@ namespace WebSocketSharp
/// </param>
public void Close (CloseStatusCode code)
{
close ((ushort) code, String.Empty);
close (new PayloadData (((ushort) code).ToByteArray (ByteOrder.BIG)));
}
/// <summary>
@ -1377,9 +1383,9 @@ namespace WebSocketSharp
/// </param>
public void Close (ushort code, string reason)
{
if (!code.IsCloseStatusCode ())
var msg = code.CheckIfValidCloseStatusCode ();
if (msg != null)
{
var msg = "Invalid close status code.";
_logger.Error (String.Format ("{0}\ncode: {1}", msg, code));
error (msg);