System.Net.Sockets.SafeSocketHandle.RegisterForBlockingSyscall C# (CSharp) Method

RegisterForBlockingSyscall() public method

public RegisterForBlockingSyscall ( ) : void
return void
		public void RegisterForBlockingSyscall ()
		{
			if (blocking_threads == null)
				Interlocked.CompareExchange (ref blocking_threads, new List<Thread> (), null);
			
			bool release = false;
			try {
				DangerousAddRef (ref release);
			} finally {
				/* We must use a finally block here to make this atomic. */
				lock (blocking_threads) {
					blocking_threads.Add (Thread.CurrentThread);
					if (THROW_ON_ABORT_RETRIES)
						threads_stacktraces.Add (Thread.CurrentThread, new StackTrace (true));
				}
				if (release)
					DangerousRelease ();

				// Handle can be closed by DangerousRelease
				if (IsClosed)
					throw new SocketException (SOCKET_CLOSED);
			}
		}

Usage Example

Example #1
0
		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 ();
			}
		}
All Usage Examples Of System.Net.Sockets.SafeSocketHandle::RegisterForBlockingSyscall