[Modify] Polish it

This commit is contained in:
sta 2020-10-16 19:38:33 +09:00
parent 067f2cd4f9
commit 34ef69cd2c

View File

@ -94,27 +94,43 @@ namespace WebSocketSharp.Net
bool reuseAddress bool reuseAddress
) )
{ {
if (secure) { _endpoint = endpoint;
var cert =
getCertificate (endpoint.Port, certificateFolderPath, sslConfig.ServerCertificate);
if (cert == null) if (secure) {
throw new ArgumentException ("No server certificate could be found."); var cert = getCertificate (
endpoint.Port,
certificateFolderPath,
sslConfig.ServerCertificate
);
if (cert == null) {
var msg = "No server certificate could be found.";
throw new ArgumentException (msg);
}
_secure = true; _secure = true;
_sslConfig = new ServerSslConfiguration (sslConfig); _sslConfig = new ServerSslConfiguration (sslConfig);
_sslConfig.ServerCertificate = cert; _sslConfig.ServerCertificate = cert;
} }
_endpoint = endpoint;
_prefixes = new Dictionary<HttpListenerPrefix, HttpListener> (); _prefixes = new Dictionary<HttpListenerPrefix, HttpListener> ();
_unregistered = new Dictionary<HttpConnection, HttpConnection> (); _unregistered = new Dictionary<HttpConnection, HttpConnection> ();
_unregisteredSync = ((ICollection) _unregistered).SyncRoot; _unregisteredSync = ((ICollection) _unregistered).SyncRoot;
_socket =
new Socket (endpoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
if (reuseAddress) _socket = new Socket (
_socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); endpoint.Address.AddressFamily,
SocketType.Stream,
ProtocolType.Tcp
);
if (reuseAddress) {
_socket.SetSocketOption (
SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress,
true
);
}
_socket.Bind (endpoint); _socket.Bind (endpoint);
_socket.Listen (500); _socket.Listen (500);