From ab9eddb3964145f764294fa5e5299e2ed6744f5d Mon Sep 17 00:00:00 2001 From: Jonas Hovgaard Date: Tue, 26 Aug 2014 14:40:36 +0200 Subject: [PATCH] Moved ReuseAddress from method to property. --- websocket-sharp/Server/WebSocketServer.cs | 43 ++++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 7e44fcff..ff849add 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -71,6 +71,7 @@ namespace WebSocketSharp.Server private volatile ServerState _state; private object _sync; private Uri _uri; + private bool _reuseAddress; #endregion @@ -451,6 +452,39 @@ namespace WebSocketSharp.Server } } + /// + /// Gets or sets a value indicating whether the server is allowed to be bound to an address + /// that is already in use. + /// + /// + /// If you would like to resolve to wait for socket TIME_WAIT, you should set this + /// property to true. + /// + /// + /// true if the server is allowed to be bound to an address that is already in use; + /// otherwise, false. The default value is false. + /// + public bool ReuseAddress + { + get + { + return _reuseAddress; + } + + set + { + if (!canSet("ReuseAddress")) + return; + + if (value ^ _reuseAddress) + { + _listener.Server.SetSocketOption( + SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, value); + + _reuseAddress = value; + } + } + } #endregion #region Private Methods @@ -840,15 +874,6 @@ namespace WebSocketSharp.Server _state = ServerState.Stop; } - - /// - /// Allows the server to be bound to an address that is already in use. - /// - public void SetReuseAddress() - { - _listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); - } - #endregion } }