Skip to content

Commit

Permalink
Add dual stack socket support
Browse files Browse the repository at this point in the history
  • Loading branch information
chronoxor committed May 22, 2020
1 parent 8d25401 commit 4ce14c9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Specify version format
version: "3.0.14.{build}"
version: "3.0.15.{build}"

# Image to use
image: Visual Studio 2019
Expand Down
2 changes: 1 addition & 1 deletion source/NetCoreServer/NetCoreServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>3.0.14</Version>
<Version>3.0.15</Version>
<Authors>Ivan Shynkarenka</Authors>
<Copyright>Copyright (c) 2019-2020 Ivan Shynkarenka</Copyright>
<RepositoryUrl>https://github.com/chronoxor/NetCoreServer</RepositoryUrl>
Expand Down
20 changes: 10 additions & 10 deletions source/NetCoreServer/SslClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public SslClient(SslContext context, IPEndPoint endpoint)
/// </summary>
public long BytesReceived { get; private set; }

/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6.
/// Will work only if socket is bound on IPv6 address.
/// </remarks>
public bool OptionDualMode { get; set; }
/// <summary>
/// Option: keep alive
/// </summary>
Expand All @@ -103,14 +111,6 @@ public SslClient(SslContext context, IPEndPoint endpoint)
/// Option: send buffer size
/// </summary>
public int OptionSendBufferSize { get; set; } = 8192;
/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6
/// Will work only if socket is bound on IPv6 address
/// </remarks>
public bool OptionDualMode { get; set; }

#region Connect/Disconnect client

Expand Down Expand Up @@ -162,7 +162,7 @@ public virtual bool Connect()
// Create a new client socket
Socket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Apply the option: dual mode; this option must be applied before connecting
// Apply the option: dual mode (this option must be applied before connecting)
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)
Socket.DualMode = OptionDualMode;

Expand Down Expand Up @@ -353,7 +353,7 @@ public virtual bool ConnectAsync()
// Create a new client socket
Socket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Apply the option: dual mode; this option must be applied before connecting
// Apply the option: dual mode (this option must be applied before connecting)
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)
Socket.DualMode = OptionDualMode;

Expand Down
18 changes: 9 additions & 9 deletions source/NetCoreServer/SslServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public SslServer(SslContext context, IPEndPoint endpoint)
/// </remarks>
public int OptionAcceptorBacklog { get; set; } = 1024;
/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6.
/// Will work only if socket is bound on IPv6 address.
/// </remarks>
public bool OptionDualMode { get; set; }
/// <summary>
/// Option: keep alive
/// </summary>
/// <remarks>
Expand Down Expand Up @@ -115,14 +123,6 @@ public SslServer(SslContext context, IPEndPoint endpoint)
/// Option: send buffer size
/// </summary>
public int OptionSendBufferSize { get; set; } = 8192;
/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6
/// Will work only if socket is bound on IPv6 address
/// </remarks>
public bool OptionDualMode { get; set; }

#region Start/Stop server

Expand Down Expand Up @@ -168,7 +168,7 @@ public virtual bool Start()
_acceptorSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, OptionReuseAddress);
// Apply the option: exclusive address use
_acceptorSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, OptionExclusiveAddressUse);
// Apply the option: dual mode; this option must be applied before listening
// Apply the option: dual mode (this option must be applied before listening)
if (_acceptorSocket.AddressFamily == AddressFamily.InterNetworkV6)
_acceptorSocket.DualMode = OptionDualMode;

Expand Down
20 changes: 10 additions & 10 deletions source/NetCoreServer/TcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public TcpClient(IPEndPoint endpoint)
/// </summary>
public long BytesReceived { get; private set; }

/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6.
/// Will work only if socket is bound on IPv6 address.
/// </remarks>
public bool OptionDualMode { get; set; }
/// <summary>
/// Option: keep alive
/// </summary>
Expand All @@ -88,14 +96,6 @@ public TcpClient(IPEndPoint endpoint)
/// Option: send buffer size
/// </summary>
public int OptionSendBufferSize { get; set; } = 8192;
/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6
/// Will work only if socket is bound on IPv6 address
/// </remarks>
public bool OptionDualMode { get; set; }

#region Connect/Disconnect client

Expand Down Expand Up @@ -140,7 +140,7 @@ public virtual bool Connect()
// Create a new client socket
Socket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Apply the option: dual mode; this option must be applied before connecting
// Apply the option: dual mode (this option must be applied before connecting)
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)
Socket.DualMode = OptionDualMode;

Expand Down Expand Up @@ -288,7 +288,7 @@ public virtual bool ConnectAsync()
// Create a new client socket
Socket = new Socket(Endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Apply the option: dual mode; this option must be applied before connecting
// Apply the option: dual mode (this option must be applied before connecting)
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)
Socket.DualMode = OptionDualMode;

Expand Down
18 changes: 9 additions & 9 deletions source/NetCoreServer/TcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ public TcpServer(IPEndPoint endpoint)
/// </remarks>
public int OptionAcceptorBacklog { get; set; } = 1024;
/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6.
/// Will work only if socket is bound on IPv6 address.
/// </remarks>
public bool OptionDualMode { get; set; }
/// <summary>
/// Option: keep alive
/// </summary>
/// <remarks>
Expand Down Expand Up @@ -106,14 +114,6 @@ public TcpServer(IPEndPoint endpoint)
/// Option: send buffer size
/// </summary>
public int OptionSendBufferSize { get; set; } = 8192;
/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6
/// Will work only if socket is bound on IPv6 address
/// </remarks>
public bool OptionDualMode { get; set; }

#region Start/Stop server

Expand Down Expand Up @@ -159,7 +159,7 @@ public virtual bool Start()
_acceptorSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, OptionReuseAddress);
// Apply the option: exclusive address use
_acceptorSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, OptionExclusiveAddressUse);
// Apply the option: dual mode; this option must be applied before listening
// Apply the option: dual mode (this option must be applied before listening)
if (_acceptorSocket.AddressFamily == AddressFamily.InterNetworkV6)
_acceptorSocket.DualMode = OptionDualMode;

Expand Down
18 changes: 9 additions & 9 deletions source/NetCoreServer/UdpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public UdpClient(IPEndPoint endpoint)
/// </summary>
public long DatagramsReceived { get; private set; }

/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6.
/// Will work only if socket is bound on IPv6 address.
/// </remarks>
public bool OptionDualMode { get; set; }
/// <summary>
/// Option: reuse address
/// </summary>
Expand All @@ -99,14 +107,6 @@ public UdpClient(IPEndPoint endpoint)
/// Option: send buffer size
/// </summary>
public int OptionSendBufferSize { get; set; } = 8192;
/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6
/// Will work only if socket is bound on IPv6 address
/// </remarks>
public bool OptionDualMode { get; set; }

#region Connect/Disconnect client

Expand Down Expand Up @@ -144,7 +144,7 @@ public virtual bool Connect()
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, OptionReuseAddress);
// Apply the option: exclusive address use
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, OptionExclusiveAddressUse);
// Apply the option: dual mode; this option must be applied before recieving/sending
// Apply the option: dual mode (this option must be applied before recieving/sending)
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)
Socket.DualMode = OptionDualMode;

Expand Down
18 changes: 9 additions & 9 deletions source/NetCoreServer/UdpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public UdpServer(IPEndPoint endpoint)
/// </summary>
public long DatagramsReceived { get; private set; }

/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6.
/// Will work only if socket is bound on IPv6 address.
/// </remarks>
public bool OptionDualMode { get; set; }
/// <summary>
/// Option: reuse address
/// </summary>
Expand All @@ -100,14 +108,6 @@ public UdpServer(IPEndPoint endpoint)
/// Option: send buffer size
/// </summary>
public int OptionSendBufferSize { get; set; } = 8192;
/// <summary>
/// Option: dual mode socket
/// </summary>
/// <remarks>
/// Specifies whether the Socket is a dual-mode socket used for both IPv4 and IPv6
/// Will work only if socket is bound on IPv6 address
/// </remarks>
public bool OptionDualMode { get; set; }

#region Connect/Disconnect client

Expand Down Expand Up @@ -146,7 +146,7 @@ public virtual bool Start()
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, OptionReuseAddress);
// Apply the option: exclusive address use
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, OptionExclusiveAddressUse);
// Apply the option: dual mode; this option must be applied before recieving
// Apply the option: dual mode (this option must be applied before recieving)
if (Socket.AddressFamily == AddressFamily.InterNetworkV6)
Socket.DualMode = OptionDualMode;

Expand Down

0 comments on commit 4ce14c9

Please sign in to comment.