@@ -45,12 +45,12 @@ internal class TcpListener : Own, IProactorEvents
4545 /// </summary>
4646 private AsyncSocket ? m_handle ;
4747
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+ */
5454
5555 /// <summary>
5656 /// Socket the listener belongs to.
@@ -107,7 +107,7 @@ protected override void ProcessPlug()
107107 protected override void ProcessTerm ( int linger )
108108 {
109109 Assumes . NotNull ( m_handle ) ;
110-
110+
111111 m_ioObject . SetHandler ( this ) ;
112112 m_ioObject . RemoveSocket ( m_handle ) ;
113113 Close ( ) ;
@@ -123,7 +123,7 @@ public virtual void SetAddress(string addr)
123123 m_address . Resolve ( addr , m_options . IPv4Only ) ;
124124
125125 Assumes . NotNull ( m_address . Address ) ;
126-
126+
127127
128128 try
129129 {
@@ -195,68 +195,75 @@ public void InCompleted(SocketError socketError, int bytesTransferred)
195195 switch ( socketError )
196196 {
197197 case SocketError . Success :
198- {
199- // TODO: check TcpFilters
200- var acceptedSocket = m_handle . GetAcceptedSocket ( ) ;
198+ {
199+ // TODO: check TcpFilters
200+ var acceptedSocket = m_handle . GetAcceptedSocket ( ) ;
201201
202202 acceptedSocket . NoDelay = true ;
203203
204- if ( m_options . TcpKeepalive != - 1 )
205- {
206- acceptedSocket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , m_options . TcpKeepalive ) ;
207-
208- if ( m_options . TcpKeepaliveIdle != - 1 && m_options . TcpKeepaliveIntvl != - 1 )
204+ if ( m_options . TcpKeepalive != - 1 )
209205 {
210- var bytes = new ByteArraySegment ( new byte [ 12 ] ) ;
206+ acceptedSocket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , m_options . TcpKeepalive ) ;
207+
208+ if ( m_options . TcpKeepaliveIdle != - 1 && m_options . TcpKeepaliveIntvl != - 1 )
209+ {
210+ var bytes = new ByteArraySegment ( new byte [ 12 ] ) ;
211+
212+ Endianness endian = BitConverter . IsLittleEndian ? Endianness . Little : Endianness . Big ;
211213
212- Endianness endian = BitConverter . IsLittleEndian ? Endianness . Little : Endianness . Big ;
214+ bytes . PutInteger ( endian , m_options . TcpKeepalive , 0 ) ;
215+ bytes . PutInteger ( endian , m_options . TcpKeepaliveIdle , 4 ) ;
216+ bytes . PutInteger ( endian , m_options . TcpKeepaliveIntvl , 8 ) ;
217+ #if NET
218+ if ( ! OperatingSystem . IsWindows ( ) )
219+ {
220+ throw new InvalidOperationException ( "Not supported on you platform" ) ; // There is a pull request for .net8.0
213221
214- bytes . PutInteger ( endian , m_options . TcpKeepalive , 0 ) ;
215- bytes . PutInteger ( endian , m_options . TcpKeepaliveIdle , 4 ) ;
216- bytes . PutInteger ( endian , m_options . TcpKeepaliveIntvl , 8 ) ;
222+ }
223+ #endif
224+ acceptedSocket . IOControl ( IOControlCode . KeepAliveValues , ( byte [ ] ) bytes , null ) ;
217225
218- acceptedSocket . IOControl ( IOControlCode . KeepAliveValues , ( byte [ ] ) bytes , null ) ;
226+ }
219227 }
220- }
221228
222- // Create the engine object for this connection.
223- var engine = new StreamEngine ( acceptedSocket , m_options , m_endpoint ) ;
229+ // Create the engine object for this connection.
230+ var engine = new StreamEngine ( acceptedSocket , m_options , m_endpoint ) ;
224231
225- // Choose I/O thread to run connector in. Given that we are already
226- // running in an I/O thread, there must be at least one available.
227- IOThread ? ioThread = ChooseIOThread ( m_options . Affinity ) ;
232+ // Choose I/O thread to run connector in. Given that we are already
233+ // running in an I/O thread, there must be at least one available.
234+ IOThread ? ioThread = ChooseIOThread ( m_options . Affinity ) ;
228235
229- Assumes . NotNull ( ioThread ) ;
236+ Assumes . NotNull ( ioThread ) ;
230237
231- // Create and launch a session object.
232- // TODO: send null in address parameter, is unneeded in this case
233- SessionBase session = SessionBase . Create ( ioThread , false , m_socket , m_options , new Address ( m_handle . LocalEndPoint ) ) ;
234- session . IncSeqnum ( ) ;
235- LaunchChild ( session ) ;
238+ // Create and launch a session object.
239+ // TODO: send null in address parameter, is unneeded in this case
240+ SessionBase session = SessionBase . Create ( ioThread , false , m_socket , m_options , new Address ( m_handle . LocalEndPoint ) ) ;
241+ session . IncSeqnum ( ) ;
242+ LaunchChild ( session ) ;
236243
237- SendAttach ( session , engine , false ) ;
244+ SendAttach ( session , engine , false ) ;
238245
239- m_socket . EventAccepted ( m_endpoint , acceptedSocket ) ;
246+ m_socket . EventAccepted ( m_endpoint , acceptedSocket ) ;
240247
241- Accept ( ) ;
242- break ;
243- }
248+ Accept ( ) ;
249+ break ;
250+ }
244251 case SocketError . ConnectionReset :
245252 case SocketError . NoBufferSpaceAvailable :
246253 case SocketError . TooManyOpenSockets :
247- {
248- m_socket . EventAcceptFailed ( m_endpoint , socketError . ToErrorCode ( ) ) ;
254+ {
255+ m_socket . EventAcceptFailed ( m_endpoint , socketError . ToErrorCode ( ) ) ;
249256
250- Accept ( ) ;
251- break ;
252- }
257+ Accept ( ) ;
258+ break ;
259+ }
253260 default :
254- {
255- NetMQException exception = NetMQException . Create ( socketError ) ;
261+ {
262+ NetMQException exception = NetMQException . Create ( socketError ) ;
256263
257- m_socket . EventAcceptFailed ( m_endpoint , exception . ErrorCode ) ;
258- throw exception ;
259- }
264+ m_socket . EventAcceptFailed ( m_endpoint , exception . ErrorCode ) ;
265+ throw exception ;
266+ }
260267 }
261268 }
262269
0 commit comments