本文整理汇总了C#中System.Net.Sockets.SocketAsyncEventArgs.StartOperationDisconnect方法的典型用法代码示例。如果您正苦于以下问题:C# SocketAsyncEventArgs.StartOperationDisconnect方法的具体用法?C# SocketAsyncEventArgs.StartOperationDisconnect怎么用?C# SocketAsyncEventArgs.StartOperationDisconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.SocketAsyncEventArgs
的用法示例。
在下文中一共展示了SocketAsyncEventArgs.StartOperationDisconnect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisconnectAsync
//
// 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;
}
示例2: DisconnectAsync
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;
}
示例3: DisconnectAsync
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;
}
示例4: DisconnectAsync
/// <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;
}
示例5: DisconnectAsync
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;
}