-
Notifications
You must be signed in to change notification settings - Fork 756
Tcp Keepalive for Linux (NET8.0) #1120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. | ||
|
||
#if !NETSTANDARD2_1 | ||
#if !NETSTANDARD2_1 && !NET8_0_OR_GREATER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
namespace System.Diagnostics.CodeAnalysis | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47 | ||
#if NET8_0_OR_GREATER || NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NET47 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I also believe a more "generic" statement like |
||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,7 @@ PullMsgResult ProduceWelcome(ref Msg msg) | |
// 8-byte prefix plus 16-byte random nonce | ||
CookieNoncePrefix.CopyTo(cookieNonce); | ||
using var rng = RandomNumberGenerator.Create(); | ||
#if NETSTANDARD2_1 | ||
#if NET8_0_OR_GREATER || NETSTANDARD2_1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
rng.GetBytes(cookieNonce.Slice(8)); | ||
#else | ||
byte[] temp = new byte[16]; | ||
|
@@ -184,7 +184,7 @@ PullMsgResult ProduceWelcome(ref Msg msg) | |
// Create full nonce for encryption | ||
// 8-byte prefix plus 16-byte random nonce | ||
WelcomeNoncePrefix.CopyTo(welcomeNonce); | ||
#if NETSTANDARD2_1 | ||
#if NET8_0_OR_GREATER || NETSTANDARD2_1 | ||
rng.GetBytes(welcomeNonce.Slice(8)); | ||
#else | ||
rng.GetBytes(temp); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,6 +248,13 @@ public void OutCompleted(SocketError socketError, int bytesTransferred) | |
// Set the TCP keep-alive option values to the underlying socket. | ||
m_s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive); | ||
|
||
|
||
#if NET8_0_OR_GREATER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last comment in the same "general" idea, these options became available in net5/netcore3.1, might be worth to do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used the #if NET idea and made a commit |
||
if (m_options.TcpKeepaliveIdle != -1) | ||
m_s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, m_options.TcpKeepaliveIdle / 1000); | ||
if (m_options.TcpKeepaliveIntvl != -1) | ||
m_s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, m_options.TcpKeepaliveIntvl / 1000); | ||
#else | ||
if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1) | ||
{ | ||
// Write the TCP keep-alive options to a byte-array, to feed to the IOControl method.. | ||
|
@@ -261,6 +268,7 @@ public void OutCompleted(SocketError socketError, int bytesTransferred) | |
|
||
m_s.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null); | ||
} | ||
#endif | ||
} | ||
|
||
// Create the engine object for this connection. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#if !NETSTANDARD2_1 | ||
#if !NETSTANDARD2_1 && !NET8_0_OR_GREATER | ||
using System; | ||
using System.Text; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IAsyncEnumerable earliest's availability is on Net Standard 2.1, I believe this check to be too restrictive in theory (although this is just a test project).
It should probably be either
#if NET
or#if NETSTANDARD2_1_OR_GREATER
?