// Sets the specified option to the specified value. public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, object optionValue) { if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } // Validate input parameters. if (optionValue == null) { throw new ArgumentNullException("optionValue"); } CheckSetOptionPermissions(optionLevel, optionName); GlobalLog.Print("Socket#" + Logging.HashString(this) + "::SetSocketOption(): optionLevel:" + optionLevel.ToString() + " optionName:" + optionName.ToString() + " optionValue:" + optionValue.ToString()); if (optionLevel == SocketOptionLevel.Socket && optionName == SocketOptionName.Linger) { LingerOption lingerOption = optionValue as LingerOption; if (lingerOption == null) { throw new ArgumentException(SR.Format(SR.net_sockets_invalid_optionValue, "LingerOption"), "optionValue"); } if (lingerOption.LingerTime < 0 || lingerOption.LingerTime > (int)UInt16.MaxValue) { throw new ArgumentException(SR.Format(SR.ArgumentOutOfRange_Bounds_Lower_Upper, 0, (int)UInt16.MaxValue), "optionValue.LingerTime"); } SetLingerOption(lingerOption); } else if (optionLevel == SocketOptionLevel.IP && (optionName == SocketOptionName.AddMembership || optionName == SocketOptionName.DropMembership)) { MulticastOption multicastOption = optionValue as MulticastOption; if (multicastOption == null) { throw new ArgumentException(SR.Format(SR.net_sockets_invalid_optionValue, "MulticastOption"), "optionValue"); } SetMulticastOption(optionName, multicastOption); } else if (optionLevel == SocketOptionLevel.IPv6 && (optionName == SocketOptionName.AddMembership || optionName == SocketOptionName.DropMembership)) { // IPv6 Changes: Handle IPv6 Multicast Add / Drop IPv6MulticastOption multicastOption = optionValue as IPv6MulticastOption; if (multicastOption == null) { throw new ArgumentException(SR.Format(SR.net_sockets_invalid_optionValue, "IPv6MulticastOption"), "optionValue"); } SetIPv6MulticastOption(optionName, multicastOption); } else { throw new ArgumentException(SR.net_sockets_invalid_optionValue_all, "optionValue"); } }
public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue) { if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } CheckSetOptionPermissions(optionLevel, optionName); GlobalLog.Print("Socket#" + Logging.HashString(this) + "::SetSocketOption(): optionLevel:" + optionLevel.ToString() + " optionName:" + optionName.ToString() + " optionValue:" + optionValue.ToString()); // This can throw ObjectDisposedException. SocketError errorCode = SocketPal.SetSockOpt(_handle, optionLevel, optionName, optionValue); GlobalLog.Print("Socket#" + Logging.HashString(this) + "::SetSocketOption() Interop.Winsock.setsockopt returns errorCode:" + errorCode); // Throw an appropriate SocketException if the native call fails. if (errorCode != SocketError.Success) { // Update the internal state of this socket according to the error before throwing. SocketException socketException = new SocketException((int)errorCode); UpdateStatusAfterSocketError(socketException); if (s_loggingEnabled) { Logging.Exception(Logging.Sockets, this, "SetSocketOption", socketException); } throw socketException; } }
// Sets the specified option to the specified value. public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue) { if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } CheckSetOptionPermissions(optionLevel, optionName); GlobalLog.Print("Socket#" + Logging.HashString(this) + "::SetSocketOption(): optionLevel:" + optionLevel.ToString() + " optionName:" + optionName.ToString() + " optionValue:" + optionValue.ToString()); SetSocketOption(optionLevel, optionName, optionValue, false); }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue) { if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } CheckSetOptionPermissions(optionLevel, optionName); GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::SetSocketOption(): optionLevel:" + optionLevel.ToString() + " optionName:" + optionName.ToString() + " optionValue:" + optionValue.ToString()); // This can throw ObjectDisposedException. SocketError errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt( m_Handle, optionLevel, optionName, optionValue, optionValue != null ? optionValue.Length : 0); GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::SetSocketOption() UnsafeNclNativeMethods.OSSOCK.setsockopt returns errorCode:" + errorCode); // // if the native call fails we'll throw a SocketException // if (errorCode==SocketError.SocketError) { // // update our internal state after this socket error and throw // SocketException socketException = new SocketException(); UpdateStatusAfterSocketError(socketException); if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "SetSocketOption", socketException); throw socketException; } }
/// <include file='doc\Socket.uex' path='docs/doc[@for="Socket.SetSocketOption2"]/*' /> /// <devdoc> /// <para>Sets the specified option to the specified value.</para> /// </devdoc> public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Object optionValue) { if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } // // parameter validation // if (optionValue==null) { throw new ArgumentNullException("optionValue"); } CheckSetOptionPermissions(optionLevel, optionName); GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::SetSocketOption(): optionLevel:" + optionLevel.ToString() + " optionName:" + optionName.ToString() + " optionValue:" + optionValue.ToString()); if (optionLevel==SocketOptionLevel.Socket && optionName==SocketOptionName.Linger) { LingerOption lingerOption = optionValue as LingerOption; if (lingerOption==null) { throw new ArgumentException("optionValue"); } if (lingerOption.LingerTime < 0 || lingerOption.LingerTime>(int)UInt16.MaxValue) { throw new ArgumentException("optionValue.LingerTime"); } setLingerOption(lingerOption); } else if (optionLevel==SocketOptionLevel.IP && (optionName==SocketOptionName.AddMembership || optionName==SocketOptionName.DropMembership)) { MulticastOption multicastOption = optionValue as MulticastOption; if (multicastOption==null) { throw new ArgumentException("optionValue"); } setMulticastOption(optionName, multicastOption); } else { throw new ArgumentException("optionValue"); } }
/// <include file='doc\Socket.uex' path='docs/doc[@for="Socket.SetSocketOption"]/*' /> /// <devdoc> /// <para> /// Sets the specified option to the specified value. /// </para> /// </devdoc> public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue) { if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } CheckSetOptionPermissions(optionLevel, optionName); GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::SetSocketOption(): optionLevel:" + optionLevel.ToString() + " optionName:" + optionName.ToString() + " optionValue:" + optionValue.ToString()); int errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt( m_Handle, optionLevel, optionName, ref optionValue, Marshal.SizeOf(optionValue)); // // if the native call fails we'll throw a SocketException // if (errorCode==SocketErrors.SocketError) { // // update our internal state after this socket error and throw // SocketException socketException = new SocketException(); UpdateStatusAfterSocketError(); throw socketException; } }