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 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); }