Skip to content

Commit fe313f1

Browse files
committed
* Update SslSession.cs
* Enable configuration of socket backlog
1 parent 3ba40c7 commit fe313f1

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

source/NetCoreServer/SslServer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public SslServer(SslContext context, IPEndPoint endpoint)
7272
/// </summary>
7373
public long BytesReceived { get { return _bytesReceived; } }
7474

75+
/// <summary>
76+
/// Option: acceptor backlog size
77+
/// </summary>
78+
/// <remarks>
79+
/// This option will set the listening socket's backlog size
80+
/// </remarks>
81+
public int OptionAcceptorBacklog { get; set; } = 1024;
7582
/// <summary>
7683
/// Option: keep alive
7784
/// </summary>
@@ -104,7 +111,6 @@ public SslServer(SslContext context, IPEndPoint endpoint)
104111
#region Start/Stop server
105112

106113
// Server acceptor
107-
private int _acceptorBacklog = 1024;
108114
private Socket _acceptorSocket;
109115
private SocketAsyncEventArgs _acceptorEventArg;
110116

@@ -153,7 +159,7 @@ public virtual bool Start()
153159
// Refresh the endpoint property based on the actual endpoint created
154160
Endpoint = (IPEndPoint)_acceptorSocket.LocalEndPoint;
155161
// Start listen to the acceptor socket with the given accepting backlog size
156-
_acceptorSocket.Listen(_acceptorBacklog);
162+
_acceptorSocket.Listen(OptionAcceptorBacklog);
157163

158164
// Reset statistic
159165
_bytesPending = 0;

source/NetCoreServer/SslSession.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Net.Security;
34
using System.Net.Sockets;
45
using System.Text;
@@ -158,8 +159,13 @@ public virtual bool Disconnect()
158159

159160
try
160161
{
161-
// Shutdown the SSL stream
162-
_sslStream.ShutdownAsync().Wait();
162+
try
163+
{
164+
// Shutdown the SSL stream
165+
_sslStream.ShutdownAsync().Wait();
166+
}
167+
catch (AggregateException) {}
168+
catch (IOException) {}
163169

164170
// Dispose the SSL stream & buffer
165171
_sslStream.Dispose();

source/NetCoreServer/TcpServer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public TcpServer(IPEndPoint endpoint)
6363
/// </summary>
6464
public long BytesReceived { get { return _bytesReceived; } }
6565

66+
/// <summary>
67+
/// Option: acceptor backlog size
68+
/// </summary>
69+
/// <remarks>
70+
/// This option will set the listening socket's backlog size
71+
/// </remarks>
72+
public int OptionAcceptorBacklog { get; set; } = 1024;
6673
/// <summary>
6774
/// Option: keep alive
6875
/// </summary>
@@ -95,7 +102,6 @@ public TcpServer(IPEndPoint endpoint)
95102
#region Start/Stop server
96103

97104
// Server acceptor
98-
private int _acceptorBacklog = 1024;
99105
private Socket _acceptorSocket;
100106
private SocketAsyncEventArgs _acceptorEventArg;
101107

@@ -144,7 +150,7 @@ public virtual bool Start()
144150
// Refresh the endpoint property based on the actual endpoint created
145151
Endpoint = (IPEndPoint)_acceptorSocket.LocalEndPoint;
146152
// Start listen to the acceptor socket with the given accepting backlog size
147-
_acceptorSocket.Listen(_acceptorBacklog);
153+
_acceptorSocket.Listen(OptionAcceptorBacklog);
148154

149155
// Reset statistic
150156
_bytesPending = 0;

0 commit comments

Comments
 (0)