public static SocketError Set(SafeSocketHandle handle, SocketOptionName optionName, int optionValueSeconds) { IOControlKeepAlive ioControlKeepAlive = s_socketKeepAliveTable.GetOrCreateValue(handle); if (optionName == SocketOptionName.TcpKeepAliveTime) { ioControlKeepAlive._timeMs = SecondsToMilliseconds(optionValueSeconds); } else { ioControlKeepAlive._intervalMs = SecondsToMilliseconds(optionValueSeconds); } byte[] buffer = s_keepAliveValuesBuffer ?? (s_keepAliveValuesBuffer = new byte[3 * sizeof(uint)]); ioControlKeepAlive.Fill(buffer); int realOptionLength = 0; return(SocketPal.WindowsIoctl(handle, unchecked ((int)IOControlCode.KeepAliveValues), buffer, null, out realOptionLength)); }
public static unsafe SocketError GetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue, ref int optionLength) { if (optionLevel == SocketOptionLevel.Tcp && (optionName == SocketOptionName.TcpKeepAliveTime || optionName == SocketOptionName.TcpKeepAliveInterval) && IOControlKeepAlive.IsNeeded) { return(IOControlKeepAlive.Get(handle, optionName, optionValue, ref optionLength)); } fixed(byte *optionValuePtr = optionValue) { SocketError errorCode = Interop.Winsock.getsockopt( handle, optionLevel, optionName, optionValuePtr, ref optionLength); return(errorCode == SocketError.SocketError ? GetLastSocketError() : SocketError.Success); } }
public static unsafe SocketError SetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue) { SocketError errorCode; if (optionLevel == SocketOptionLevel.Tcp && (optionName == SocketOptionName.TcpKeepAliveTime || optionName == SocketOptionName.TcpKeepAliveInterval) && IOControlKeepAlive.IsNeeded) { errorCode = IOControlKeepAlive.Set(handle, optionName, optionValue); } else { errorCode = Interop.Winsock.setsockopt( handle, optionLevel, optionName, ref optionValue, sizeof(int)); } return(errorCode == SocketError.SocketError ? GetLastSocketError() : SocketError.Success); }
public static unsafe SocketError GetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, out int optionValue) { if (optionLevel == SocketOptionLevel.Tcp && (optionName == SocketOptionName.TcpKeepAliveTime || optionName == SocketOptionName.TcpKeepAliveInterval) && IOControlKeepAlive.IsNeeded) { optionValue = IOControlKeepAlive.Get(handle, optionName); return(SocketError.Success); } int optionLength = sizeof(int); int tmpOptionValue = 0; SocketError errorCode = Interop.Winsock.getsockopt( handle, optionLevel, optionName, (byte *)&tmpOptionValue, ref optionLength); optionValue = tmpOptionValue; return(errorCode == SocketError.SocketError ? GetLastSocketError() : SocketError.Success); }