Modified the HttpServer class, fix for 'No Status Code' for the stop

This commit is contained in:
sta 2015-01-28 14:58:22 +09:00
parent 22c1e8e3ad
commit 5c64c3c90e

View File

@ -749,20 +749,15 @@ namespace WebSocketSharp.Server
/// <see cref="string"/> used to stop the WebSocket services. /// <see cref="string"/> used to stop the WebSocket services.
/// </summary> /// </summary>
/// <param name="code"> /// <param name="code">
/// A <see cref="ushort"/> that represents the status code indicating the reason for stop. /// A <see cref="ushort"/> that represents the status code indicating the reason for the stop.
/// </param> /// </param>
/// <param name="reason"> /// <param name="reason">
/// A <see cref="string"/> that represents the reason for stop. /// A <see cref="string"/> that represents the reason for the stop.
/// </param> /// </param>
public void Stop (ushort code, string reason) public void Stop (ushort code, string reason)
{ {
CloseEventArgs e = null;
lock (_sync) { lock (_sync) {
var msg = var msg = _state.CheckIfStart () ?? code.CheckIfValidCloseParameters (reason);
_state.CheckIfStart () ??
code.CheckIfValidCloseStatusCode () ??
(e = new CloseEventArgs (code, reason)).RawData.CheckIfValidControlData ("reason");
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);
return; return;
@ -771,8 +766,13 @@ namespace WebSocketSharp.Server
_state = ServerState.ShuttingDown; _state = ServerState.ShuttingDown;
} }
if (code.IsNoStatusCode ()) {
_services.Stop (new CloseEventArgs (), true, true);
}
else {
var send = !code.IsReserved (); var send = !code.IsReserved ();
_services.Stop (e, send, send); _services.Stop (new CloseEventArgs (code, reason), send, send);
}
stopReceiving (5000); stopReceiving (5000);
@ -785,19 +785,15 @@ namespace WebSocketSharp.Server
/// </summary> /// </summary>
/// <param name="code"> /// <param name="code">
/// One of the <see cref="CloseStatusCode"/> enum values, represents the status code /// One of the <see cref="CloseStatusCode"/> enum values, represents the status code
/// indicating the reasons for stop. /// indicating the reason for the stop.
/// </param> /// </param>
/// <param name="reason"> /// <param name="reason">
/// A <see cref="string"/> that represents the reason for stop. /// A <see cref="string"/> that represents the reason for the stop.
/// </param> /// </param>
public void Stop (CloseStatusCode code, string reason) public void Stop (CloseStatusCode code, string reason)
{ {
CloseEventArgs e = null;
lock (_sync) { lock (_sync) {
var msg = var msg = _state.CheckIfStart () ?? code.CheckIfValidCloseParameters (reason);
_state.CheckIfStart () ??
(e = new CloseEventArgs (code, reason)).RawData.CheckIfValidControlData ("reason");
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);
return; return;
@ -806,8 +802,13 @@ namespace WebSocketSharp.Server
_state = ServerState.ShuttingDown; _state = ServerState.ShuttingDown;
} }
if (code.IsNoStatusCode ()) {
_services.Stop (new CloseEventArgs (), true, true);
}
else {
var send = !code.IsReserved (); var send = !code.IsReserved ();
_services.Stop (e, send, send); _services.Stop (new CloseEventArgs (code, reason), send, send);
}
stopReceiving (5000); stopReceiving (5000);