本文整理汇总了C#中SocketOptionName.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SocketOptionName.ToString方法的具体用法?C# SocketOptionName.ToString怎么用?C# SocketOptionName.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketOptionName
的用法示例。
在下文中一共展示了SocketOptionName.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetSocketOption
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;
}
}
示例2: setIPv6MulticastOption
/// <devdoc>
/// <para>
/// IPv6 setsockopt for JOIN / LEAVE multicast group
/// </para>
/// </devdoc>
private void setIPv6MulticastOption(SocketOptionName optionName, IPv6MulticastOption MR) {
IPv6MulticastRequest ipmr = new IPv6MulticastRequest();
ipmr.MulticastAddress = MR.Group.GetAddressBytes();
ipmr.InterfaceIndex = unchecked((int)MR.InterfaceIndex);
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setIPv6MulticastOption(): optionName:" + optionName.ToString() + " MR:" + MR.ToString() + " ipmr:" + ipmr.ToString() + " IPv6MulticastRequest.Size:" + IPv6MulticastRequest.Size.ToString());
// This can throw ObjectDisposedException.
SocketError errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt(
m_Handle,
SocketOptionLevel.IPv6,
optionName,
ref ipmr,
IPv6MulticastRequest.Size);
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setIPv6MulticastOption() 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, "setIPv6MulticastOption", socketException);
throw socketException;
}
}
示例3: setMulticastOption
private void setMulticastOption(SocketOptionName optionName, MulticastOption MR) {
IPMulticastRequest ipmr = new IPMulticastRequest();
ipmr.MulticastAddress = unchecked((int)MR.Group.m_Address);
if(MR.LocalAddress != null){
ipmr.InterfaceAddress = unchecked((int)MR.LocalAddress.m_Address);
}
else { //this structure works w/ interfaces as well
int ifIndex =IPAddress.HostToNetworkOrder(MR.InterfaceIndex);
ipmr.InterfaceAddress = unchecked((int)ifIndex);
}
#if BIGENDIAN
ipmr.MulticastAddress = (int) (((uint) ipmr.MulticastAddress << 24) |
(((uint) ipmr.MulticastAddress & 0x0000FF00) << 8) |
(((uint) ipmr.MulticastAddress >> 8) & 0x0000FF00) |
((uint) ipmr.MulticastAddress >> 24));
if(MR.LocalAddress != null){
ipmr.InterfaceAddress = (int) (((uint) ipmr.InterfaceAddress << 24) |
(((uint) ipmr.InterfaceAddress & 0x0000FF00) << 8) |
(((uint) ipmr.InterfaceAddress >> 8) & 0x0000FF00) |
((uint) ipmr.InterfaceAddress >> 24));
}
#endif // BIGENDIAN
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption(): optionName:" + optionName.ToString() + " MR:" + MR.ToString() + " ipmr:" + ipmr.ToString() + " IPMulticastRequest.Size:" + IPMulticastRequest.Size.ToString());
// This can throw ObjectDisposedException.
SocketError errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt(
m_Handle,
SocketOptionLevel.IP,
optionName,
ref ipmr,
IPMulticastRequest.Size);
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption() 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, "setMulticastOption", socketException);
throw socketException;
}
}
示例4: 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;
}
}
示例5: setMulticastOption
private void setMulticastOption(SocketOptionName optionName, MulticastOption MR) {
IPMulticastRequest ipmr = new IPMulticastRequest();
ipmr.MulticastAddress = unchecked((int)MR.Group.Address);
ipmr.InterfaceAddress = unchecked((int)MR.LocalAddress.Address);
#if BIGENDIAN
ipmr.MulticastAddress = (int) (((uint) ipmr.MulticastAddress << 24) |
(((uint) ipmr.MulticastAddress & 0x0000FF00) << 8) |
(((uint) ipmr.MulticastAddress >> 8) & 0x0000FF00) |
((uint) ipmr.MulticastAddress >> 24));
ipmr.InterfaceAddress = (int) (((uint) ipmr.InterfaceAddress << 24) |
(((uint) ipmr.InterfaceAddress & 0x0000FF00) << 8) |
(((uint) ipmr.InterfaceAddress >> 8) & 0x0000FF00) |
((uint) ipmr.InterfaceAddress >> 24));
#endif // BIGENDIAN
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption(): optionName:" + optionName.ToString() + " MR:" + MR.ToString() + " ipmr:" + ipmr.ToString() + " IPMulticastRequest.Size:" + IPMulticastRequest.Size.ToString());
int errorCode =
UnsafeNclNativeMethods.OSSOCK.setsockopt(
m_Handle,
SocketOptionLevel.IP,
optionName,
ref ipmr,
IPMulticastRequest.Size );
//
// 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;
}
}
示例6: 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");
}
}