From ab29d4db4fc75073f24e338a4cdee15bf47089a6 Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 19 May 2016 16:30:54 +0900 Subject: [PATCH] [Fix] Throw invalid operation exception --- websocket-sharp/Net/HttpListenerContext.cs | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/websocket-sharp/Net/HttpListenerContext.cs b/websocket-sharp/Net/HttpListenerContext.cs index 3546406b..911718b7 100644 --- a/websocket-sharp/Net/HttpListenerContext.cs +++ b/websocket-sharp/Net/HttpListenerContext.cs @@ -54,13 +54,14 @@ namespace WebSocketSharp.Net { #region Private Fields - private HttpConnection _connection; - private string _error; - private int _errorStatus; - private HttpListener _listener; - private HttpListenerRequest _request; - private HttpListenerResponse _response; - private IPrincipal _user; + private HttpConnection _connection; + private string _error; + private int _errorStatus; + private HttpListener _listener; + private HttpListenerRequest _request; + private HttpListenerResponse _response; + private IPrincipal _user; + private HttpListenerWebSocketContext _websocketContext; #endregion @@ -220,8 +221,14 @@ namespace WebSocketSharp.Net /// contains an invalid character. /// /// + /// + /// This method has already been called. + /// 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