diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 57b43193..198e6af3 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -201,6 +201,13 @@ namespace WebSocketSharp } } + internal static string CheckIfCanAccept (this WebSocketState state) + { + return state != WebSocketState.Connecting + ? "This operation has already been done." + : null; + } + internal static string CheckIfCanRead (this Stream stream) { return stream == null diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 76b69990..551d4749 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -592,6 +592,32 @@ namespace WebSocketSharp #region Private Methods + // As server + private bool accept () + { + lock (_forConn) { + var msg = _readyState.CheckIfCanAccept (); + if (msg != null) { + _logger.Error (msg); + error ("An error has occurred in accepting.", null); + + return false; + } + + try { + if (acceptHandshake ()) { + _readyState = WebSocketState.Open; + return true; + } + } + catch (Exception ex) { + processException (ex, "An exception has occurred while accepting."); + } + + return false; + } + } + // As server private bool acceptHandshake () {