本文整理汇总了C#中System.Net.Sockets.SafeSocketHandle类的典型用法代码示例。如果您正苦于以下问题:C# SafeSocketHandle类的具体用法?C# SafeSocketHandle怎么用?C# SafeSocketHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SafeSocketHandle类属于System.Net.Sockets命名空间,在下文中一共展示了SafeSocketHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send_internal
static int Send_internal (SafeSocketHandle safeHandle, byte[] buf, int offset, int count, SocketFlags flags, out int error, bool blocking)
{
try {
safeHandle.RegisterForBlockingSyscall ();
return Send_internal (safeHandle.DangerousGetHandle (), buf, offset, count, flags, out error, blocking);
} finally {
safeHandle.UnRegisterForBlockingSyscall ();
}
}
示例2: Available_internal
static int Available_internal (SafeSocketHandle safeHandle, out int error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return Available_internal (safeHandle.DangerousGetHandle (), out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
示例3: RemoteEndPoint_internal
static SocketAddress RemoteEndPoint_internal (SafeSocketHandle safeHandle, int family, out int error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return RemoteEndPoint_internal (safeHandle.DangerousGetHandle (), family, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
示例4: IOControl_internal
static int IOControl_internal (SafeSocketHandle safeHandle, int ioctl_code, byte [] input, byte [] output, out int error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
return IOControl_internal (safeHandle.DangerousGetHandle (), ioctl_code, input, output, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
示例5: Socket
/* private constructor used by Accept, which already has a socket handle to use */
internal Socket(AddressFamily family, SocketType type, ProtocolType proto, SafeSocketHandle safe_handle)
{
this.address_family = family;
this.socket_type = type;
this.protocol_type = proto;
this.safe_handle = safe_handle;
this.is_connected = true;
}
示例6: SendTo_internal
static int SendTo_internal (SafeSocketHandle safeHandle, byte[] buffer, int offset, int count, SocketFlags flags, SocketAddress sa, out int error)
{
try {
safeHandle.RegisterForBlockingSyscall ();
return SendTo_internal (safeHandle.DangerousGetHandle (), buffer, offset, count, flags, sa, out error);
} finally {
safeHandle.UnRegisterForBlockingSyscall ();
}
}
示例7: RecvFrom_internal
private static int RecvFrom_internal (SafeSocketHandle safeHandle,
byte[] buffer,
int offset,
int count,
SocketFlags flags,
ref SocketAddress sockaddr,
out int error)
{
try {
safeHandle.RegisterForBlockingSyscall ();
return RecvFrom_internal (safeHandle.DangerousGetHandle (), buffer, offset, count, flags, ref sockaddr, out error);
} finally {
safeHandle.UnRegisterForBlockingSyscall ();
}
}
示例8: Socket
public Socket (SocketInformation socketInformation)
{
var options = socketInformation.Options;
islistening = (options & SocketInformationOptions.Listening) != 0;
connected = (options & SocketInformationOptions.Connected) != 0;
blocking = (options & SocketInformationOptions.NonBlocking) == 0;
useoverlappedIO = (options & SocketInformationOptions.UseOnlyOverlappedIO) != 0;
var result = Mono.DataConverter.Unpack ("iiiil", socketInformation.ProtocolInformation, 0);
address_family = (AddressFamily) (int) result [0];
socket_type = (SocketType) (int) result [1];
protocol_type = (ProtocolType) (int) result [2];
isbound = (ProtocolType) (int) result [3] != 0;
socket = new SafeSocketHandle ((IntPtr) (long) result [4], true);
SocketDefaults ();
}
示例9: GetSocketOption_arr_internal
private static void GetSocketOption_arr_internal (SafeSocketHandle safeHandle,
SocketOptionLevel level, SocketOptionName name, ref byte[] byte_val,
out int error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
GetSocketOption_arr_internal (safeHandle.DangerousGetHandle (), level, name, ref byte_val, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}
示例10: BeginConnect
IAsyncResult BeginConnect(EndPoint end_point, AsyncCallback callback, object state)
{
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (end_point == null)
throw new ArgumentNullException ("end_point");
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Connect);
req.EndPoint = end_point;
// Bug #75154: Connect() should not succeed for .Any addresses.
if (end_point is IPEndPoint) {
IPEndPoint ep = (IPEndPoint) end_point;
if (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any)) {
req.Complete (new SocketException ((int) SocketError.AddressNotAvailable), true);
return req;
}
}
int error = 0;
if (connect_in_progress) {
// This could happen when multiple IPs are used
// Calling connect() again will reset the connection attempt and cause
// an error. Better to just close the socket and move on.
connect_in_progress = false;
socket.Dispose ();
var handle = Socket_internal (address_family, socket_type, protocol_type, out error);
socket = new SafeSocketHandle (handle, true);
if (error != 0)
throw new SocketException (error);
}
bool blk = blocking;
if (blk)
Blocking = false;
SocketAddress serial = end_point.Serialize ();
Connect_internal (socket, serial, out error);
if (blk)
Blocking = true;
if (error == 0) {
// succeeded synch
connected = true;
isbound = true;
req.Complete (true);
return req;
}
if (error != (int) SocketError.InProgress && error != (int) SocketError.WouldBlock) {
// error synch
connected = false;
isbound = false;
req.Complete (new SocketException (error), true);
return req;
}
// continue asynch
connected = false;
isbound = false;
connect_in_progress = true;
socket_pool_queue (Worker.Dispatcher, req);
return req;
}
示例11: EnsureSocket
//internal Socket (AddressFamily family, SocketType type, ProtocolType proto, IntPtr sock)
bool EnsureSocket ()
{
lock (_lock) {
if (nl_sock != null)
return true;
IntPtr fd = CreateNLSocket ();
if (fd.ToInt64 () == -1)
return false;
var safeHandle = new SafeSocketHandle (fd, true);
nl_sock = new Socket (0, SocketType.Raw, ProtocolType.Udp, safeHandle);
nl_args = new SocketAsyncEventArgs ();
nl_args.SetBuffer (new byte [8192], 0, 8192);
nl_args.Completed += OnDataAvailable;
nl_sock.ReceiveAsync (nl_args);
}
return true;
}
示例12: Socket
public Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
{
this.address_family = addressFamily;
this.socket_type = socketType;
this.protocol_type = protocolType;
int error;
this.safe_handle = new SafeSocketHandle (Socket_internal (addressFamily, socketType, protocolType, out error), true);
if (error != 0)
throw new SocketException (error);
SocketDefaults ();
}
示例13: Receive_internal
static int Receive_internal (SafeSocketHandle safeHandle, WSABUF[] bufarray, SocketFlags flags, out int error)
{
try {
safeHandle.RegisterForBlockingSyscall ();
return Receive_internal (safeHandle.DangerousGetHandle (), bufarray, flags, out error);
} finally {
safeHandle.UnRegisterForBlockingSyscall ();
}
}
示例14: Accept_internal
static SafeSocketHandle Accept_internal (SafeSocketHandle safeHandle, out int error, bool blocking)
{
try {
safeHandle.RegisterForBlockingSyscall ();
var ret = Accept_internal (safeHandle.DangerousGetHandle (), out error, blocking);
return new SafeSocketHandle (ret, true);
} finally {
safeHandle.UnRegisterForBlockingSyscall ();
}
}
示例15: Bind_internal
private static void Bind_internal (SafeSocketHandle safeHandle, SocketAddress sa, out int error)
{
bool release = false;
try {
safeHandle.DangerousAddRef (ref release);
Bind_internal (safeHandle.DangerousGetHandle (), sa, out error);
} finally {
if (release)
safeHandle.DangerousRelease ();
}
}