// // DisconnectAsync // public bool DisconnectAsync(SocketAsyncEventArgs e) { bool retval; if(s_LoggingEnabled) Logging.Enter(Logging.Sockets, this, "DisconnectAsync", ""); // Throw if socket disposed if(CleanedUp) { throw new ObjectDisposedException(GetType().FullName); } // Prepare for the native call. e.StartOperationCommon(this); e.StartOperationDisconnect(); BindToCompletionPort(); // Make the native call. SocketError socketError = SocketError.Success; try { if(!DisconnectEx( m_Handle, e.m_PtrNativeOverlapped, (int)(e.DisconnectReuseSocket ? TransmitFileOptions.ReuseSocket : 0), 0)) { socketError = (SocketError)Marshal.GetLastWin32Error(); } } catch(Exception ex) { // clear in-use on event arg object e.Complete(); throw ex; } // Handle completion when completion port is not posted. if(socketError != SocketError.Success && socketError != SocketError.IOPending) { e.FinishOperationSyncFailure(socketError, 0, SocketFlags.None); retval = false; } else { retval = true; } if(s_LoggingEnabled) Logging.Exit(Logging.Sockets, this, "DisconnectAsync", retval); return retval; }
public bool DisconnectAsync(SocketAsyncEventArgs e) { bool retval; if (s_loggingEnabled) { Logging.Enter(Logging.Sockets, this, "DisconnectAsync", ""); } if (CleanedUp) { throw new ObjectDisposedException(GetType().FullName); } if (e == null) { throw new ArgumentNullException("e"); } // Prepare for the native call. e.StartOperationCommon(this); e.StartOperationDisconnect(); // Make the native call. SocketError socketError = SocketError.Success; try { socketError = e.DoOperationDisconnect(this, _handle); } catch (Exception ex) { // Clear in-use flag on event args object. e.Complete(); throw ex; } // Handle completion when completion port is not posted. if (socketError != SocketError.Success && socketError != SocketError.IOPending) { e.FinishOperationSyncFailure(socketError, 0, SocketFlags.None); retval = false; } else { retval = true; } if (s_loggingEnabled) { Logging.Exit(Logging.Sockets, this, "DisconnectAsync", retval); } return retval; }
public bool DisconnectAsync(SocketAsyncEventArgs e) { if (NetEventSource.IsEnabled) NetEventSource.Enter(this); bool retval; // Throw if socket disposed if (CleanedUp) { throw new ObjectDisposedException(GetType().FullName); } // Prepare for the native call. e.StartOperationCommon(this); e.StartOperationDisconnect(); SocketError socketError = SocketError.Success; try { socketError = e.DoOperationDisconnect(this, _handle); } catch { // clear in-use on event arg object e.Complete(); throw; } // Handle completion when completion port is not posted. if (socketError != SocketError.Success && socketError != SocketError.IOPending) { e.FinishOperationSyncFailure(socketError, 0, SocketFlags.None); retval = false; } else { retval = true; } if (NetEventSource.IsEnabled) NetEventSource.Exit(this, retval); return retval; }
/// <summary> /// Begins an asynchronous request to disconnect from a remote endpoint. /// </summary> /// /// <returns> /// Returns true if the I/O operation is pending. The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed"/> event on the <paramref name="e"/> parameter will be raised upon completion of the operation. Returns false if the I/O operation completed synchronously. In this case, The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed"/> event on the <paramref name="e"/> parameter will not be raised and the <paramref name="e"/> object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation. /// </returns> /// <param name="e">The <see cref="T:System.Net.Sockets.SocketAsyncEventArgs"/> object to use for this asynchronous socket operation.</param><exception cref="T:System.ArgumentNullException">The <paramref name="e"/> parameter cannot be null.</exception><exception cref="T:System.InvalidOperationException">A socket operation was already in progress using the <see cref="T:System.Net.Sockets.SocketAsyncEventArgs"/> object specified in the <paramref name="e"/> parameter.</exception><exception cref="T:System.NotSupportedException">Windows XP or later is required for this method.</exception><exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.Socket"/> has been closed. </exception><exception cref="T:System.Net.Sockets.SocketException">An error occurred when attempting to access the socket. </exception> public bool DisconnectAsync(SocketAsyncEventArgs e) { if (Socket.s_LoggingEnabled) Logging.Enter(Logging.Sockets, (object) this, "DisconnectAsync", ""); if (this.CleanedUp) throw new ObjectDisposedException(this.GetType().FullName); e.StartOperationCommon(this); e.StartOperationDisconnect(); this.BindToCompletionPort(); SocketError socketError = SocketError.Success; try { if (!this.DisconnectEx(this.m_Handle, (SafeHandle) e.m_PtrNativeOverlapped, e.DisconnectReuseSocket ? 2 : 0, 0)) socketError = (SocketError) Marshal.GetLastWin32Error(); } catch (Exception ex) { e.Complete(); throw ex; } bool flag; if (socketError != SocketError.Success && socketError != SocketError.IOPending) { e.FinishOperationSyncFailure(socketError, 0, SocketFlags.None); flag = false; } else flag = true; if (Socket.s_LoggingEnabled) Logging.Exit(Logging.Sockets, (object) this, "DisconnectAsync", (object) (bool) (flag ? 1 : 0)); return flag; }
public bool DisconnectAsync(SocketAsyncEventArgs e) { bool flag; if (s_LoggingEnabled) { Logging.Enter(Logging.Sockets, this, "DisconnectAsync", ""); } if (this.CleanedUp) { throw new ObjectDisposedException(base.GetType().FullName); } e.StartOperationCommon(this); e.StartOperationDisconnect(); this.BindToCompletionPort(); SocketError success = SocketError.Success; try { if (!this.DisconnectEx(this.m_Handle, e.m_PtrNativeOverlapped, e.DisconnectReuseSocket ? 2 : 0, 0)) { success = (SocketError) Marshal.GetLastWin32Error(); } } catch (Exception exception) { e.Complete(); throw exception; } if ((success != SocketError.Success) && (success != SocketError.IOPending)) { e.FinishOperationSyncFailure(success, 0, SocketFlags.None); flag = false; } else { flag = true; } if (s_LoggingEnabled) { Logging.Exit(Logging.Sockets, this, "DisconnectAsync", flag); } return flag; }