@@ -22,7 +22,7 @@ You should have received a copy of the GNU Lesser General Public License
22
22
using System ;
23
23
using System . Diagnostics ;
24
24
using System . Net . Sockets ;
25
- #if NETSTANDARD2_0 || NETSTANDARD2_1
25
+ #if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1
26
26
using System . Runtime . InteropServices ;
27
27
#endif
28
28
using AsyncIO ;
@@ -45,12 +45,12 @@ internal class TcpListener : Own, IProactorEvents
45
45
/// </summary>
46
46
private AsyncSocket ? m_handle ;
47
47
48
- /*
49
- /// <summary>
50
- /// socket being accepted
51
- /// </summary>
52
- private AsyncSocket m_acceptedSocket;
53
- */
48
+ /*
49
+ /// <summary>
50
+ /// socket being accepted
51
+ /// </summary>
52
+ private AsyncSocket m_acceptedSocket;
53
+ */
54
54
55
55
/// <summary>
56
56
/// Socket the listener belongs to.
@@ -107,7 +107,7 @@ protected override void ProcessPlug()
107
107
protected override void ProcessTerm ( int linger )
108
108
{
109
109
Assumes . NotNull ( m_handle ) ;
110
-
110
+
111
111
m_ioObject . SetHandler ( this ) ;
112
112
m_ioObject . RemoveSocket ( m_handle ) ;
113
113
Close ( ) ;
@@ -141,7 +141,7 @@ public virtual void SetAddress(string addr)
141
141
}
142
142
}
143
143
144
- #if NETSTANDARD2_0 || NETSTANDARD2_1
144
+ #if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1
145
145
// This command is failing on linux
146
146
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
147
147
m_handle . ExclusiveAddressUse = false ;
@@ -194,68 +194,75 @@ public void InCompleted(SocketError socketError, int bytesTransferred)
194
194
switch ( socketError )
195
195
{
196
196
case SocketError . Success :
197
- {
198
- // TODO: check TcpFilters
199
- var acceptedSocket = m_handle . GetAcceptedSocket ( ) ;
197
+ {
198
+ // TODO: check TcpFilters
199
+ var acceptedSocket = m_handle . GetAcceptedSocket ( ) ;
200
200
201
201
acceptedSocket . NoDelay = true ;
202
202
203
- if ( m_options . TcpKeepalive != - 1 )
204
- {
205
- acceptedSocket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , m_options . TcpKeepalive ) ;
206
-
207
- if ( m_options . TcpKeepaliveIdle != - 1 && m_options . TcpKeepaliveIntvl != - 1 )
203
+ if ( m_options . TcpKeepalive != - 1 )
208
204
{
209
- var bytes = new ByteArraySegment ( new byte [ 12 ] ) ;
205
+ acceptedSocket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , m_options . TcpKeepalive ) ;
206
+
207
+ if ( m_options . TcpKeepaliveIdle != - 1 && m_options . TcpKeepaliveIntvl != - 1 )
208
+ {
209
+ #if NET8_0_OR_GREATER
210
+ if ( m_options . TcpKeepaliveIdle != - 1 )
211
+ acceptedSocket . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveTime , m_options . TcpKeepaliveIdle / 1000 ) ;
212
+ if ( m_options . TcpKeepaliveIntvl != - 1 )
213
+ acceptedSocket . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . TcpKeepAliveInterval , m_options . TcpKeepaliveIntvl / 1000 ) ;
214
+ #else
215
+ var bytes = new ByteArraySegment ( new byte [ 12 ] ) ;
210
216
211
- Endianness endian = BitConverter . IsLittleEndian ? Endianness . Little : Endianness . Big ;
217
+ Endianness endian = BitConverter . IsLittleEndian ? Endianness . Little : Endianness . Big ;
212
218
213
- bytes . PutInteger ( endian , m_options . TcpKeepalive , 0 ) ;
214
- bytes . PutInteger ( endian , m_options . TcpKeepaliveIdle , 4 ) ;
215
- bytes . PutInteger ( endian , m_options . TcpKeepaliveIntvl , 8 ) ;
219
+ bytes . PutInteger ( endian , m_options . TcpKeepalive , 0 ) ;
220
+ bytes . PutInteger ( endian , m_options . TcpKeepaliveIdle , 4 ) ;
221
+ bytes . PutInteger ( endian , m_options . TcpKeepaliveIntvl , 8 ) ;
216
222
217
- acceptedSocket . IOControl ( IOControlCode . KeepAliveValues , ( byte [ ] ) bytes , null ) ;
223
+ acceptedSocket . IOControl ( IOControlCode . KeepAliveValues , ( byte [ ] ) bytes , null ) ;
224
+ #endif
225
+ }
218
226
}
219
- }
220
227
221
- // Create the engine object for this connection.
222
- var engine = new StreamEngine ( acceptedSocket , m_options , m_endpoint ) ;
228
+ // Create the engine object for this connection.
229
+ var engine = new StreamEngine ( acceptedSocket , m_options , m_endpoint ) ;
223
230
224
- // Choose I/O thread to run connector in. Given that we are already
225
- // running in an I/O thread, there must be at least one available.
226
- IOThread ? ioThread = ChooseIOThread ( m_options . Affinity ) ;
231
+ // Choose I/O thread to run connector in. Given that we are already
232
+ // running in an I/O thread, there must be at least one available.
233
+ IOThread ? ioThread = ChooseIOThread ( m_options . Affinity ) ;
227
234
228
- Assumes . NotNull ( ioThread ) ;
235
+ Assumes . NotNull ( ioThread ) ;
229
236
230
- // Create and launch a session object.
231
- // TODO: send null in address parameter, is unneeded in this case
232
- SessionBase session = SessionBase . Create ( ioThread , false , m_socket , m_options , new Address ( m_handle . LocalEndPoint ) ) ;
233
- session . IncSeqnum ( ) ;
234
- LaunchChild ( session ) ;
237
+ // Create and launch a session object.
238
+ // TODO: send null in address parameter, is unneeded in this case
239
+ SessionBase session = SessionBase . Create ( ioThread , false , m_socket , m_options , new Address ( m_handle . LocalEndPoint ) ) ;
240
+ session . IncSeqnum ( ) ;
241
+ LaunchChild ( session ) ;
235
242
236
- SendAttach ( session , engine , false ) ;
243
+ SendAttach ( session , engine , false ) ;
237
244
238
- m_socket . EventAccepted ( m_endpoint , acceptedSocket ) ;
245
+ m_socket . EventAccepted ( m_endpoint , acceptedSocket ) ;
239
246
240
- Accept ( ) ;
241
- break ;
242
- }
247
+ Accept ( ) ;
248
+ break ;
249
+ }
243
250
case SocketError . ConnectionReset :
244
251
case SocketError . NoBufferSpaceAvailable :
245
252
case SocketError . TooManyOpenSockets :
246
- {
247
- m_socket . EventAcceptFailed ( m_endpoint , socketError . ToErrorCode ( ) ) ;
253
+ {
254
+ m_socket . EventAcceptFailed ( m_endpoint , socketError . ToErrorCode ( ) ) ;
248
255
249
- Accept ( ) ;
250
- break ;
251
- }
256
+ Accept ( ) ;
257
+ break ;
258
+ }
252
259
default :
253
- {
254
- NetMQException exception = NetMQException . Create ( socketError ) ;
260
+ {
261
+ NetMQException exception = NetMQException . Create ( socketError ) ;
255
262
256
- m_socket . EventAcceptFailed ( m_endpoint , exception . ErrorCode ) ;
257
- throw exception ;
258
- }
263
+ m_socket . EventAcceptFailed ( m_endpoint , exception . ErrorCode ) ;
264
+ throw exception ;
265
+ }
259
266
}
260
267
}
261
268
0 commit comments