Added the ReuseAddress property to the HttpServer class (Associated with pull request #73)
This commit is contained in:
parent
4cfdd7e793
commit
7a8967bdcd
@ -72,6 +72,9 @@ namespace Example3
|
|||||||
// Not to remove the inactive WebSocket sessions periodically.
|
// Not to remove the inactive WebSocket sessions periodically.
|
||||||
//httpsv.KeepClean = false;
|
//httpsv.KeepClean = false;
|
||||||
|
|
||||||
|
// To resolve to wait for socket in TIME_WAIT state.
|
||||||
|
//httpsv.ReuseAddress = true;
|
||||||
|
|
||||||
// Add the WebSocket services.
|
// Add the WebSocket services.
|
||||||
httpsv.AddWebSocketService<Echo> ("/Echo");
|
httpsv.AddWebSocketService<Echo> ("/Echo");
|
||||||
httpsv.AddWebSocketService<Chat> ("/Chat");
|
httpsv.AddWebSocketService<Chat> ("/Chat");
|
||||||
|
@ -83,7 +83,8 @@ namespace WebSocketSharp.Net
|
|||||||
int port,
|
int port,
|
||||||
bool secure,
|
bool secure,
|
||||||
string certificateFolderPath,
|
string certificateFolderPath,
|
||||||
X509Certificate2 defaultCertificate)
|
X509Certificate2 defaultCertificate,
|
||||||
|
bool reuseAddress)
|
||||||
{
|
{
|
||||||
if (secure) {
|
if (secure) {
|
||||||
_secure = secure;
|
_secure = secure;
|
||||||
@ -92,13 +93,16 @@ namespace WebSocketSharp.Net
|
|||||||
throw new ArgumentException ("No server certificate could be found.");
|
throw new ArgumentException ("No server certificate could be found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_endpoint = new IPEndPoint (address, port);
|
|
||||||
_prefixes = new Dictionary<ListenerPrefix, HttpListener> ();
|
_prefixes = new Dictionary<ListenerPrefix, HttpListener> ();
|
||||||
|
|
||||||
_unregistered = new Dictionary<HttpConnection, HttpConnection> ();
|
_unregistered = new Dictionary<HttpConnection, HttpConnection> ();
|
||||||
_unregisteredSync = ((ICollection) _unregistered).SyncRoot;
|
_unregisteredSync = ((ICollection) _unregistered).SyncRoot;
|
||||||
|
|
||||||
_socket = new Socket (address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
_socket = new Socket (address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
if (reuseAddress)
|
||||||
|
_socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||||
|
|
||||||
|
_endpoint = new IPEndPoint (address, port);
|
||||||
_socket.Bind (_endpoint);
|
_socket.Bind (_endpoint);
|
||||||
_socket.Listen (500);
|
_socket.Listen (500);
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ namespace WebSocketSharp.Net
|
|||||||
port,
|
port,
|
||||||
secure,
|
secure,
|
||||||
httpListener.CertificateFolderPath,
|
httpListener.CertificateFolderPath,
|
||||||
httpListener.DefaultCertificate);
|
httpListener.DefaultCertificate,
|
||||||
|
httpListener.ReuseAddress);
|
||||||
|
|
||||||
eps[port] = epl;
|
eps[port] = epl;
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ namespace WebSocketSharp.Net
|
|||||||
private bool _listening;
|
private bool _listening;
|
||||||
private HttpListenerPrefixCollection _prefixes;
|
private HttpListenerPrefixCollection _prefixes;
|
||||||
private string _realm;
|
private string _realm;
|
||||||
|
private bool _reuseAddress;
|
||||||
private List<ListenerAsyncResult> _waitQueue;
|
private List<ListenerAsyncResult> _waitQueue;
|
||||||
private object _waitQueueSync;
|
private object _waitQueueSync;
|
||||||
|
|
||||||
@ -109,6 +110,16 @@ namespace WebSocketSharp.Net
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal bool ReuseAddress {
|
||||||
|
get {
|
||||||
|
return _reuseAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_reuseAddress = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
@ -306,6 +306,34 @@ namespace WebSocketSharp.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the server is allowed to be bound to an address
|
||||||
|
/// that is already in use.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// If you would like to resolve to wait for socket in <c>TIME_WAIT</c> state, you should set
|
||||||
|
/// this property to <c>true</c>.
|
||||||
|
/// </remarks>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> if the server is allowed to be bound to an address that is already in use;
|
||||||
|
/// otherwise, <c>false</c>. The default value is <c>false</c>.
|
||||||
|
/// </value>
|
||||||
|
public bool ReuseAddress {
|
||||||
|
get {
|
||||||
|
return _listener.ReuseAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
var msg = _state.CheckIfStartable ();
|
||||||
|
if (msg != null) {
|
||||||
|
_logger.Error (msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_listener.ReuseAddress = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the document root path of the server.
|
/// Gets or sets the document root path of the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user