本文整理汇总了C#中SocketOptionName类的典型用法代码示例。如果您正苦于以下问题:C# SocketOptionName类的具体用法?C# SocketOptionName怎么用?C# SocketOptionName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketOptionName类属于命名空间,在下文中一共展示了SocketOptionName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetSocketOption
protected static int SetSocketOption(Socket socket, SocketOptionLevel level, SocketOptionName name, int value)
{
if (((int)socket.GetSocketOption(level, name)) == value)
return value;
socket.SetSocketOption(level, name, value);
return (int)socket.GetSocketOption(level, name);
}
示例2: SetSocketOption
protected void SetSocketOption(SocketOptionLevel level, SocketOptionName name, int option)
{
try
{
m_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, option);
}
catch { }
}
示例3: SetSocketOption
protected static bool SetSocketOption(Socket socket, SocketOptionLevel level, SocketOptionName name, bool value) {
if (((int)socket.GetSocketOption(level, name)) == (value ? 1 : 0))
return value;
socket.SetSocketOption(level, name, value);
if (((int)socket.GetSocketOption(level, name)) != 1) {
return false;
}
return true;
}
示例4: SetSocketOption
protected void SetSocketOption(SocketOptionLevel level, SocketOptionName name, int val)
{
try
{
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, val);
}
catch
{
}
}
示例5: SetSockOpt
internal static unsafe Error SetSockOpt(SafeHandle socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int optionLen)
{
bool release = false;
try
{
socket.DangerousAddRef(ref release);
return DangerousSetSockOpt((int)socket.DangerousGetHandle(), optionLevel, optionName, optionValue, optionLen);
}
finally
{
if (release)
{
socket.DangerousRelease();
}
}
}
示例6: SetSocketOption
public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, bool optionValue)
{
if (optionName == SocketOptionName.ReuseAddress)
{
if (this.InternalServerSocket != null)
{
try
{
//Console.WriteLine("setReuseAddress... " + new { optionValue });
this.InternalServerSocket.setReuseAddress(optionValue);
}
catch
{
throw;
}
}
}
}
示例7: 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;
}
}
示例8: GetIPv6MulticastOpt
// IPv6 getsockopt for JOIN / LEAVE multicast group.
private IPv6MulticastOption GetIPv6MulticastOpt(SocketOptionName optionName)
{
IPv6MulticastOption multicastOption;
SocketError errorCode = SocketPal.GetIPv6MulticastOption(_handle, optionName, out multicastOption);
GlobalLog.Print("Socket#" + Logging.HashString(this) + "::getIPv6MulticastOpt() Interop.Winsock.getsockopt 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, "getIPv6MulticastOpt", socketException);
}
throw socketException;
}
return multicastOption;
}
示例9: SetSocketOption_internal
extern static void SetSocketOption_internal (IntPtr socket, SocketOptionLevel level, SocketOptionName name, object obj_val, byte [] byte_val, int int_val, out int error);
示例10: SetSocketOption
public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue)
{
ThrowIfDisposedAndClosed ();
int error;
SetSocketOption_internal (safe_handle, optionLevel, optionName, null, null, optionValue, out error);
if (error != 0) {
throw new SocketException (error);
}
}
示例11: GetSocketOption_obj_internal
extern static void GetSocketOption_obj_internal(IntPtr socket, SocketOptionLevel level, SocketOptionName name, out object obj_val, out int error);
示例12: GetSocketOption
public object GetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName)
{
ThrowIfDisposedAndClosed ();
int error;
object obj_val;
GetSocketOption_obj_internal (safe_handle, optionLevel, optionName, out obj_val, out error);
if (error != 0)
throw new SocketException (error);
if (optionName == SocketOptionName.Linger)
return (LingerOption) obj_val;
else if (optionName == SocketOptionName.AddMembership || optionName == SocketOptionName.DropMembership)
return (MulticastOption) obj_val;
else if (obj_val is int)
return (int) obj_val;
else
return obj_val;
}
示例13: numericOption
private int numericOption(SocketOptionLevel optionLevel, SocketOptionName optionName) {
return (int)Client.GetSocketOption(optionLevel, optionName);
}
示例14: SetSocketOption
public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, bool optionValue)
{
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
int error;
int int_val = (optionValue) ? 1 : 0;
SetSocketOption_internal (socket, optionLevel, optionName, null, null, int_val, out error);
if (error != 0) {
if (error == (int) SocketError.InvalidArgument)
throw new ArgumentException ();
throw new SocketException (error);
}
}
示例15: GetSocketOption_arr_internal
extern static void GetSocketOption_arr_internal(IntPtr socket, SocketOptionLevel level, SocketOptionName name, ref byte[] byte_val, out int error);