本文整理汇总了C#中SocketOptionLevel.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SocketOptionLevel.ToString方法的具体用法?C# SocketOptionLevel.ToString怎么用?C# SocketOptionLevel.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketOptionLevel
的用法示例。
在下文中一共展示了SocketOptionLevel.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetSocketOption
// 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");
}
}
示例2: SetSocketOption
/// <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;
}
}
示例3: SetSocketOption
/// <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");
}
}