﻿// Decompiled with JetBrains decompiler
// Type: InvokedCommon.Extensions.SocketExtensions
// Assembly: InvokedCommon, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: A935EE8A-7FFF-4BAB-94FD-31AEC4036FB9
// Assembly location: C:\Users\ian\Downloads\Telegram Desktop\fein\InvokedCommon.dll

using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;


namespace InvokedCommon.Extensions
{
	public static class SocketExtensions
	{
		public static void SetKeepAliveEx(
			this Socket socket,
			uint keepAliveInterval,
			uint keepAliveTime)
		{
			SocketExtensions.TcpKeepAlive structure = new SocketExtensions.TcpKeepAlive()
			{
				onoff = 1,
				keepaliveinterval = keepAliveInterval,
				keepalivetime = keepAliveTime
			};
			int length = Marshal.SizeOf<SocketExtensions.TcpKeepAlive>(structure);
			IntPtr num = Marshal.AllocHGlobal(length);
			Marshal.StructureToPtr<SocketExtensions.TcpKeepAlive>(structure, num, true);
			byte[] numArray = new byte[length];
			Marshal.Copy(num, numArray, 0, length);
			Marshal.FreeHGlobal(num);
			socket.IOControl(IOControlCode.KeepAliveValues, numArray, (byte[]) null);
		}

		internal struct TcpKeepAlive
		{
			internal uint onoff;
			internal uint keepalivetime;
			internal uint keepaliveinterval;
		}
	}
}
