-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IsConnected & KeepAlive extension method.
- Loading branch information
Showing
10 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<Project> | ||
<PropertyGroup Condition="'$(AssemblyName)'=='GodSharp.Socket'"> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>1.0.2-preview1</Version> | ||
<Version>1.0.2-preview2</Version> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using GodSharp.Sockets.Internal.Extension; | ||
using System; | ||
using System.Net.Sockets; | ||
|
||
namespace GodSharp.Sockets | ||
{ | ||
/// <summary> | ||
/// Extension class. | ||
/// </summary> | ||
public static class Extensions | ||
{ | ||
/// <summary> | ||
/// Determines whether this instance is connected. | ||
/// </summary> | ||
/// <param name="client">The client.</param> | ||
/// <returns> | ||
/// <c>true</c> if the specified client is connected; otherwise, <c>false</c>. | ||
/// </returns> | ||
public static bool IsConnected(this SocketBase client) | ||
{ | ||
return client.socket.IsConnected(); | ||
} | ||
|
||
/// <summary> | ||
/// Set <see cref="SocketClient"/> keep-alive option. | ||
/// </summary> | ||
/// <param name="client">The socket client.</param> | ||
/// <param name="on">if set to <c>true</c> [on].</param> | ||
/// <param name="time">The time.</param> | ||
/// <param name="interval">The interval.</param> | ||
/// <returns>return <see cref="bool"/> value of KeepAlive value.</returns> | ||
public static bool KeepAlive(this SocketBase client, bool on = true, uint time = 5000, uint interval = 5000) | ||
{ | ||
try | ||
{ | ||
byte[] inOptionValues = new byte[12]; | ||
|
||
uint off = (uint)(on ? 1 : 0); | ||
|
||
BitConverter.GetBytes(off).CopyTo(inOptionValues, 0); | ||
BitConverter.GetBytes(interval).CopyTo(inOptionValues, 4); | ||
BitConverter.GetBytes(interval).CopyTo(inOptionValues, 8); | ||
|
||
client.socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null); | ||
|
||
object obj = client.socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive); | ||
|
||
return Convert.ToInt32(obj) == 1; | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
namespace GodSharp.Sockets | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class KeepAliveOptions | ||
{ | ||
/// <summary> | ||
|