本文整理汇总了C#中System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSyncFailure方法的典型用法代码示例。如果您正苦于以下问题:C# SocketAsyncEventArgs.FinishOperationSyncFailure方法的具体用法?C# SocketAsyncEventArgs.FinishOperationSyncFailure怎么用?C# SocketAsyncEventArgs.FinishOperationSyncFailure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.SocketAsyncEventArgs
的用法示例。
在下文中一共展示了SocketAsyncEventArgs.FinishOperationSyncFailure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: SendPacketsAsync
public bool SendPacketsAsync(SocketAsyncEventArgs e)
{
bool retval;
if (s_loggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "SendPacketsAsync", "");
}
// Throw if socket disposed
if (CleanedUp)
{
throw new ObjectDisposedException(GetType().FullName);
}
if (e == null)
{
throw new ArgumentNullException("e");
}
if (e.SendPacketsElements == null)
{
throw new ArgumentNullException("e.SendPacketsElements");
}
if (!Connected)
{
throw new NotSupportedException(SR.net_notconnected);
}
// Prepare for the native call.
e.StartOperationCommon(this);
e.StartOperationSendPackets();
// Make the native call.
SocketError socketError;
Debug.Assert(e.SendPacketsDescriptorCount != null);
if (e.SendPacketsDescriptorCount > 0)
{
try
{
socketError = e.DoOperationSendPackets(this, _handle);
}
catch (Exception)
{
// Clear in-use flag on event args 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;
}
}
else
{
// No buffers or files to send.
e.FinishOperationSuccess(SocketError.Success, 0, SocketFlags.None);
retval = false;
}
if (s_loggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "SendPacketsAsync", retval);
}
return retval;
}
示例3: 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;
}
示例4: AcceptAsync
public bool AcceptAsync(SocketAsyncEventArgs e)
{
bool retval;
if (s_loggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "AcceptAsync", "");
}
if (CleanedUp)
{
throw new ObjectDisposedException(GetType().FullName);
}
if (e == null)
{
throw new ArgumentNullException("e");
}
if (e._bufferList != null)
{
throw new ArgumentException(SR.net_multibuffernotsupported, "BufferList");
}
if (_rightEndPoint == null)
{
throw new InvalidOperationException(SR.net_sockets_mustbind);
}
if (!_isListening)
{
throw new InvalidOperationException(SR.net_sockets_mustlisten);
}
// Handle AcceptSocket property.
SafeCloseSocket acceptHandle;
e.AcceptSocket = GetOrCreateAcceptSocket(e.AcceptSocket, true, "AcceptSocket", out acceptHandle);
// Prepare for the native call.
e.StartOperationCommon(this);
e.StartOperationAccept();
// Local variables for sync completion.
int bytesTransferred;
SocketError socketError = SocketError.Success;
// Make the native call.
try
{
socketError = e.DoOperationAccept(this, _handle, acceptHandle, out bytesTransferred);
}
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, bytesTransferred, SocketFlags.None);
retval = false;
}
else
{
retval = true;
}
if (s_loggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "AcceptAsync", retval);
}
return retval;
}
示例5: ReceiveAsync
public bool ReceiveAsync(SocketAsyncEventArgs e)
{
bool retval;
if (s_loggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "ReceiveAsync", "");
}
if (CleanedUp)
{
throw new ObjectDisposedException(GetType().FullName);
}
if (e == null)
{
throw new ArgumentNullException("e");
}
// Prepare for the native call.
e.StartOperationCommon(this);
e.StartOperationReceive();
// Local vars for sync completion of native call.
SocketFlags flags;
int bytesTransferred;
SocketError socketError;
// Wrap native methods with try/catch so event args object can be cleaned up.
try
{
socketError = e.DoOperationReceive(_handle, out flags, out bytesTransferred);
}
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, bytesTransferred, flags);
retval = false;
}
else
{
retval = true;
}
if (s_loggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "ReceiveAsync", retval);
}
return retval;
}
示例6: ReceiveAsync
//
// ReceiveAsync
//
public bool ReceiveAsync(SocketAsyncEventArgs e) {
bool retval;
if(s_LoggingEnabled) Logging.Enter(Logging.Sockets, this, "ReceiveAsync", "");
// Throw if socket disposed
if(CleanedUp) {
throw new ObjectDisposedException(GetType().FullName);
}
// Prepare for the native call.
e.StartOperationCommon(this);
e.StartOperationReceive();
BindToCompletionPort();
// Local vars for [....] completion of native call.
SocketFlags flags = e.m_SocketFlags;
int bytesTransferred;
SocketError socketError;
// Wrap native methods with try/catch so event args object can be cleaned up
try {
if(e.m_Buffer != null) {
// Single buffer case
socketError = UnsafeNclNativeMethods.OSSOCK.WSARecv(
m_Handle,
ref e.m_WSABuffer,
1,
out bytesTransferred,
ref flags,
e.m_PtrNativeOverlapped,
IntPtr.Zero);
} else {
// Multi buffer case
socketError = UnsafeNclNativeMethods.OSSOCK.WSARecv(
m_Handle,
e.m_WSABufferArray,
e.m_WSABufferArray.Length,
out bytesTransferred,
ref flags,
e.m_PtrNativeOverlapped,
IntPtr.Zero);
}
}
catch(Exception ex) {
// clear in-use on event arg object
e.Complete();
throw ex;
}
// Native method emits single catch-all error code when error occurs.
// Must get Win32 error for specific error code.
if(socketError != SocketError.Success) {
socketError = (SocketError)Marshal.GetLastWin32Error();
}
// Handle completion when completion port is not posted.
if(socketError != SocketError.Success && socketError != SocketError.IOPending) {
e.FinishOperationSyncFailure(socketError, bytesTransferred, flags);
retval = false;
} else {
retval = true;
}
if(s_LoggingEnabled) Logging.Exit(Logging.Sockets, this, "ReceiveAsync", retval);
return retval;
}
示例7: SendPacketsAsync
//
// SendPacketsAsync
//
public bool SendPacketsAsync(SocketAsyncEventArgs e) {
bool retval;
if(s_LoggingEnabled) Logging.Enter(Logging.Sockets, this, "SendPacketsAsync", "");
// Throw if socket disposed
if(CleanedUp) {
throw new ObjectDisposedException(GetType().FullName);
}
// Throw if not connected.
if(!Connected) {
throw new NotSupportedException(SR.GetString(SR.net_notconnected));
}
// Prepare for the native call.
e.StartOperationCommon(this);
e.StartOperationSendPackets();
BindToCompletionPort();
// Make the native call.
SocketError socketError;
bool result;
if (e.m_SendPacketsDescriptor.Length > 0) {
try {
result = TransmitPackets(
m_Handle,
e.m_PtrSendPacketsDescriptor,
e.m_SendPacketsDescriptor.Length,
e.m_SendPacketsSendSize,
e.m_PtrNativeOverlapped,
e.m_SendPacketsFlags);
}
catch(Exception) {
// clear in-use on event arg object
e.Complete();
throw;
}
if(!result) {
socketError = (SocketError)Marshal.GetLastWin32Error();
} else {
socketError = SocketError.Success;
}
// 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;
}
}
else {
// No buffers or files to send.
e.FinishOperationSuccess(SocketError.Success, 0, SocketFlags.None);
retval = false;
}
if(s_LoggingEnabled) Logging.Exit(Logging.Sockets, this, "SendPacketsAsync", retval);
return retval;
}
示例8: 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;
}
示例9: SendAsync
public bool SendAsync(SocketAsyncEventArgs e)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, e);
bool retval;
if (CleanedUp)
{
throw new ObjectDisposedException(GetType().FullName);
}
if (e == null)
{
throw new ArgumentNullException(nameof(e));
}
// Prepare for the native call.
e.StartOperationCommon(this);
e.StartOperationSend();
// Local vars for sync completion of native call.
int bytesTransferred;
SocketError socketError;
// Wrap native methods with try/catch so event args object can be cleaned up.
try
{
socketError = e.DoOperationSend(_handle, out bytesTransferred);
}
catch
{
// Clear in-use flag on event args object.
e.Complete();
throw;
}
// Handle completion when completion port is not posted.
if (socketError != SocketError.Success && socketError != SocketError.IOPending)
{
e.FinishOperationSyncFailure(socketError, bytesTransferred, SocketFlags.None);
retval = false;
}
else
{
retval = true;
}
if (NetEventSource.IsEnabled) NetEventSource.Exit(this, retval);
return retval;
}
示例10: SendPacketsAsync
public bool SendPacketsAsync(SocketAsyncEventArgs e)
{
bool flag;
SocketError success;
bool flag2;
if (s_LoggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "SendPacketsAsync", "");
}
if (this.CleanedUp)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (!this.Connected)
{
throw new NotSupportedException(SR.GetString("net_notconnected"));
}
e.StartOperationCommon(this);
e.StartOperationSendPackets();
this.BindToCompletionPort();
try
{
flag2 = this.TransmitPackets(this.m_Handle, e.m_PtrSendPacketsDescriptor, e.m_SendPacketsElements.Length, e.m_SendPacketsSendSize, e.m_PtrNativeOverlapped, e.m_SendPacketsFlags);
}
catch (Exception exception)
{
e.Complete();
throw exception;
}
if (!flag2)
{
success = (SocketError) Marshal.GetLastWin32Error();
}
else
{
success = SocketError.Success;
}
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, "SendPacketsAsync", flag);
}
return flag;
}
示例11: SendToAsync
public bool SendToAsync(SocketAsyncEventArgs e)
{
bool flag;
int num;
SocketError error;
if (s_LoggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "SendToAsync", "");
}
if (this.CleanedUp)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (e.RemoteEndPoint == null)
{
throw new ArgumentNullException("RemoteEndPoint");
}
EndPoint remoteEndPoint = e.RemoteEndPoint;
e.m_SocketAddress = this.CheckCacheRemote(ref remoteEndPoint, false);
e.StartOperationCommon(this);
e.StartOperationSendTo();
this.BindToCompletionPort();
try
{
if (e.m_Buffer != null)
{
error = UnsafeNclNativeMethods.OSSOCK.WSASendTo(this.m_Handle, ref e.m_WSABuffer, 1, out num, e.m_SocketFlags, e.m_PtrSocketAddressBuffer, e.m_SocketAddress.m_Size, e.m_PtrNativeOverlapped, IntPtr.Zero);
}
else
{
error = UnsafeNclNativeMethods.OSSOCK.WSASendTo(this.m_Handle, e.m_WSABufferArray, e.m_WSABufferArray.Length, out num, e.m_SocketFlags, e.m_PtrSocketAddressBuffer, e.m_SocketAddress.m_Size, e.m_PtrNativeOverlapped, IntPtr.Zero);
}
}
catch (Exception exception)
{
e.Complete();
throw exception;
}
if (error != SocketError.Success)
{
error = (SocketError) Marshal.GetLastWin32Error();
}
if ((error != SocketError.Success) && (error != SocketError.IOPending))
{
e.FinishOperationSyncFailure(error, num, SocketFlags.None);
flag = false;
}
else
{
flag = true;
}
if (s_LoggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "SendToAsync", flag);
}
return flag;
}
示例12: ReceiveMessageFromAsync
public bool ReceiveMessageFromAsync(SocketAsyncEventArgs e)
{
bool flag;
int num;
SocketError error;
if (s_LoggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "ReceiveMessageFromAsync", "");
}
if (this.CleanedUp)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (e.RemoteEndPoint == null)
{
throw new ArgumentNullException("RemoteEndPoint");
}
if (e.RemoteEndPoint.AddressFamily != this.addressFamily)
{
throw new ArgumentException(SR.GetString("net_InvalidEndPointAddressFamily", new object[] { e.RemoteEndPoint.AddressFamily, this.addressFamily }), "RemoteEndPoint");
}
EndPoint remoteEndPoint = e.RemoteEndPoint;
e.m_SocketAddress = this.SnapshotAndSerialize(ref remoteEndPoint);
this.SetReceivingPacketInformation();
e.StartOperationCommon(this);
e.StartOperationReceiveMessageFrom();
this.BindToCompletionPort();
try
{
error = this.WSARecvMsg(this.m_Handle, e.m_PtrWSAMessageBuffer, out num, e.m_PtrNativeOverlapped, IntPtr.Zero);
}
catch (Exception exception)
{
e.Complete();
throw exception;
}
if (error != SocketError.Success)
{
error = (SocketError) Marshal.GetLastWin32Error();
}
if ((error != SocketError.Success) && (error != SocketError.IOPending))
{
e.FinishOperationSyncFailure(error, num, SocketFlags.None);
flag = false;
}
else
{
flag = true;
}
if (s_LoggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "ReceiveMessageFromAsync", flag);
}
return flag;
}
示例13: ReceiveAsync
public bool ReceiveAsync(SocketAsyncEventArgs e)
{
bool flag;
int num;
SocketError error;
if (s_LoggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "ReceiveAsync", "");
}
if (this.CleanedUp)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
e.StartOperationCommon(this);
e.StartOperationReceive();
this.BindToCompletionPort();
SocketFlags socketFlags = e.m_SocketFlags;
try
{
if (e.m_Buffer != null)
{
error = UnsafeNclNativeMethods.OSSOCK.WSARecv(this.m_Handle, ref e.m_WSABuffer, 1, out num, ref socketFlags, e.m_PtrNativeOverlapped, IntPtr.Zero);
}
else
{
error = UnsafeNclNativeMethods.OSSOCK.WSARecv(this.m_Handle, e.m_WSABufferArray, e.m_WSABufferArray.Length, out num, ref socketFlags, e.m_PtrNativeOverlapped, IntPtr.Zero);
}
}
catch (Exception exception)
{
e.Complete();
throw exception;
}
if (error != SocketError.Success)
{
error = (SocketError) Marshal.GetLastWin32Error();
}
if ((error != SocketError.Success) && (error != SocketError.IOPending))
{
e.FinishOperationSyncFailure(error, num, socketFlags);
flag = false;
}
else
{
flag = true;
}
if (s_LoggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "ReceiveAsync", flag);
}
return flag;
}
示例14: AcceptAsync
public bool AcceptAsync(SocketAsyncEventArgs e)
{
bool flag;
int num;
if (s_LoggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "AcceptAsync", "");
}
if (this.CleanedUp)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (e.m_BufferList != null)
{
throw new ArgumentException(SR.GetString("net_multibuffernotsupported"), "BufferList");
}
if (this.m_RightEndPoint == null)
{
throw new InvalidOperationException(SR.GetString("net_sockets_mustbind"));
}
if (!this.isListening)
{
throw new InvalidOperationException(SR.GetString("net_sockets_mustlisten"));
}
if (e.AcceptSocket == null)
{
e.AcceptSocket = new Socket(this.addressFamily, this.socketType, this.protocolType);
}
else if ((e.AcceptSocket.m_RightEndPoint != null) && !e.AcceptSocket.m_IsDisconnected)
{
throw new InvalidOperationException(SR.GetString("net_sockets_namedmustnotbebound", new object[] { "AcceptSocket" }));
}
e.StartOperationCommon(this);
e.StartOperationAccept();
this.BindToCompletionPort();
SocketError success = SocketError.Success;
try
{
if (!this.AcceptEx(this.m_Handle, e.AcceptSocket.m_Handle, (e.m_PtrSingleBuffer != IntPtr.Zero) ? e.m_PtrSingleBuffer : e.m_PtrAcceptBuffer, (e.m_PtrSingleBuffer != IntPtr.Zero) ? (e.Count - e.m_AcceptAddressBufferCount) : 0, e.m_AcceptAddressBufferCount / 2, e.m_AcceptAddressBufferCount / 2, out num, e.m_PtrNativeOverlapped))
{
success = (SocketError) Marshal.GetLastWin32Error();
}
}
catch (Exception exception)
{
e.Complete();
throw exception;
}
if ((success != SocketError.Success) && (success != SocketError.IOPending))
{
e.FinishOperationSyncFailure(success, num, SocketFlags.None);
flag = false;
}
else
{
flag = true;
}
if (s_LoggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "AcceptAsync", flag);
}
return flag;
}
示例15: AcceptAsync
//
// AcceptAsync
//
public bool AcceptAsync(SocketAsyncEventArgs e) {
bool retval;
if(s_LoggingEnabled) Logging.Enter(Logging.Sockets, this, "AcceptAsync", "");
// Throw if socket disposed
if(CleanedUp) {
throw new ObjectDisposedException(GetType().FullName);
}
// Throw if multiple buffers specified.
if(e.m_BufferList != null) {
throw new ArgumentException(SR.GetString(SR.net_multibuffernotsupported), "BufferList");
}
// Throw if not bound.
if(m_RightEndPoint == null) {
throw new InvalidOperationException(SR.GetString(SR.net_sockets_mustbind));
}
// Throw if not listening.
if(!isListening) {
throw new InvalidOperationException(SR.GetString(SR.net_sockets_mustlisten));
}
// Handle AcceptSocket property.
if(e.AcceptSocket == null) {
// Accept socket not specified - create it.
e.AcceptSocket = new Socket(addressFamily, socketType, protocolType);
} else {
// Validate accept socket for use here.
if(e.AcceptSocket.m_RightEndPoint != null && !e.AcceptSocket.m_IsDisconnected) {
throw new InvalidOperationException(SR.GetString(SR.net_sockets_namedmustnotbebound, "AcceptSocket"));
}
}
// Prepare for the native call.
e.StartOperationCommon(this);
e.StartOperationAccept();
BindToCompletionPort();
// Local variables for [....] completion.
int bytesTransferred;
SocketError socketError = SocketError.Success;
// Make the native call.
try {
if(!AcceptEx(
m_Handle,
e.AcceptSocket.m_Handle,
(e.m_PtrSingleBuffer != IntPtr.Zero) ? e.m_PtrSingleBuffer : e.m_PtrAcceptBuffer,
(e.m_PtrSingleBuffer != IntPtr.Zero) ? e.Count - e.m_AcceptAddressBufferCount : 0,
e.m_AcceptAddressBufferCount / 2,
e.m_AcceptAddressBufferCount / 2,
out bytesTransferred,
e.m_PtrNativeOverlapped)) {
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, bytesTransferred, SocketFlags.None);
retval = false;
} else {
retval = true;
}
if(s_LoggingEnabled) Logging.Exit(Logging.Sockets, this, "AcceptAsync", retval);
return retval;
}