[Fix] Throw invalid operation exception

This commit is contained in:
sta 2016-05-19 16:30:54 +09:00
parent cd964a5987
commit ab29d4db4f

View File

@ -61,6 +61,7 @@ namespace WebSocketSharp.Net
private HttpListenerRequest _request;
private HttpListenerResponse _response;
private IPrincipal _user;
private HttpListenerWebSocketContext _websocketContext;
#endregion
@ -220,8 +221,14 @@ namespace WebSocketSharp.Net
/// <paramref name="protocol"/> contains an invalid character.
/// </para>
/// </exception>
/// <exception cref="InvalidOperationException">
/// This method has already been called.
/// </exception>
public HttpListenerWebSocketContext AcceptWebSocket (string protocol)
{
if (_websocketContext != null)
throw new InvalidOperationException ("The accepting is already in progress.");
if (protocol != null) {
if (protocol.Length == 0)
throw new ArgumentException ("An empty string.", "protocol");
@ -230,7 +237,8 @@ namespace WebSocketSharp.Net
throw new ArgumentException ("Contains an invalid character.", "protocol");
}
return new HttpListenerWebSocketContext (this, protocol);
_websocketContext = new HttpListenerWebSocketContext (this, protocol);
return _websocketContext;
}
#endregion