本文整理汇总了C#中System.Net.Sockets.OverlappedAsyncResult.InvokeCallback方法的典型用法代码示例。如果您正苦于以下问题:C# OverlappedAsyncResult.InvokeCallback方法的具体用法?C# OverlappedAsyncResult.InvokeCallback怎么用?C# OverlappedAsyncResult.InvokeCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.OverlappedAsyncResult
的用法示例。
在下文中一共展示了OverlappedAsyncResult.InvokeCallback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoBeginReceive
private SocketError DoBeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
GlobalLog.Print("Socket#" + Logging.HashString(this) + "::BeginReceive() size:" + size.ToString());
#if DEBUG
IntPtr lastHandle = _handle.DangerousGetHandle();
#endif
// Guarantee to call CheckAsyncCallOverlappedResult if we call SetUnamangedStructures with a cache in order to
// avoid a Socket leak in case of error.
SocketError errorCode = SocketError.SocketError;
try
{
errorCode = SocketPal.ReceiveAsync(_handle, buffer, offset, size, socketFlags, asyncResult);
GlobalLog.Print("Socket#" + Logging.HashString(this) + "::BeginReceive() Interop.Winsock.WSARecv returns:" + errorCode.ToString() + " returning AsyncResult:" + Logging.HashString(asyncResult));
}
finally
{
errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
}
// Throw an appropriate SocketException if the native call fails synchronously.
if (errorCode != SocketError.Success)
{
GlobalLog.Assert(errorCode != SocketError.Success, "Socket#{0}::DoBeginReceive()|GetLastWin32Error() returned zero.", Logging.HashString(this));
// Update the internal state of this socket according to the error before throwing.
UpdateStatusAfterSocketError(errorCode);
if (s_loggingEnabled)
{
Logging.Exception(Logging.Sockets, this, "BeginReceive", new SocketException((int)errorCode));
}
asyncResult.InvokeCallback(new SocketException((int)errorCode));
}
#if DEBUG
else
{
_lastReceiveHandle = lastHandle;
_lastReceiveThread = Environment.CurrentManagedThreadId;
_lastReceiveTick = Environment.TickCount;
}
#endif
return errorCode;
}
示例2: DoBeginReceive
private SocketError DoBeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
SocketError socketError = SocketError.SocketError;
try
{
asyncResult.SetUnmanagedStructures(buffer, offset, size, (SocketAddress) null, false, ref this.Caches.ReceiveOverlappedCache);
int bytesTransferred;
socketError = UnsafeNclNativeMethods.OSSOCK.WSARecv(this.m_Handle, ref asyncResult.m_SingleBuffer, 1, out bytesTransferred, out socketFlags, asyncResult.OverlappedHandle, IntPtr.Zero);
if (socketError != SocketError.Success)
socketError = (SocketError) Marshal.GetLastWin32Error();
}
finally
{
socketError = asyncResult.CheckAsyncCallOverlappedResult(socketError);
}
if (socketError != SocketError.Success)
{
asyncResult.ExtractCache(ref this.Caches.ReceiveOverlappedCache);
this.UpdateStatusAfterSocketError(socketError);
if (Socket.s_LoggingEnabled)
Logging.Exception(Logging.Sockets, (object) this, "BeginReceive", (Exception) new SocketException(socketError));
asyncResult.InvokeCallback((object) new SocketException(socketError));
}
return socketError;
}
示例3: DoBeginReceive
private SocketError DoBeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::BeginReceive() size:" + size.ToString());
#if DEBUG
IntPtr lastHandle = m_Handle.DangerousGetHandle();
#endif
// Guarantee to call CheckAsyncCallOverlappedResult if we call SetUnamangedStructures with a cache in order to
// avoid a Socket leak in case of error.
SocketError errorCode = SocketError.SocketError;
try
{
// Set up asyncResult for overlapped WSARecv.
// This call will use completion ports on WinNT and Overlapped IO on Win9x.
asyncResult.SetUnmanagedStructures(buffer, offset, size, null, false /* don't pin null RemoteEP*/, ref Caches.ReceiveOverlappedCache);
// This can throw ObjectDisposedException.
int bytesTransferred;
errorCode = UnsafeNclNativeMethods.OSSOCK.WSARecv(
m_Handle,
ref asyncResult.m_SingleBuffer,
1,
out bytesTransferred,
ref socketFlags,
asyncResult.OverlappedHandle,
IntPtr.Zero);
if (errorCode!=SocketError.Success) {
errorCode = (SocketError)Marshal.GetLastWin32Error();
GlobalLog.Assert(errorCode != SocketError.Success, "Socket#{0}::DoBeginReceive()|GetLastWin32Error() returned zero.", ValidationHelper.HashString(this));
}
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::BeginReceive() UnsafeNclNativeMethods.OSSOCK.WSARecv returns:" + errorCode.ToString() + " bytesTransferred:" + bytesTransferred.ToString() + " returning AsyncResult:" + ValidationHelper.HashString(asyncResult));
}
finally
{
errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
}
//
// if the asynchronous native call fails synchronously
// we'll throw a SocketException
//
if (errorCode != SocketError.Success)
{
//
// update our internal state after this socket error and throw
asyncResult.ExtractCache(ref Caches.ReceiveOverlappedCache);
UpdateStatusAfterSocketError(errorCode);
if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "BeginReceive", new SocketException(errorCode));
asyncResult.InvokeCallback(new SocketException(errorCode));
}
#if DEBUG
else
{
m_LastReceiveHandle = lastHandle;
m_LastReceiveThread = Thread.CurrentThread.ManagedThreadId;
m_LastReceiveTick = Environment.TickCount;
}
#endif
return errorCode;
}
示例4: DoBeginReceive
private SocketError DoBeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"size:{size}");
#if DEBUG
IntPtr lastHandle = _handle.DangerousGetHandle();
#endif
// Guarantee to call CheckAsyncCallOverlappedResult if we call SetUnamangedStructures with a cache in order to
// avoid a Socket leak in case of error.
SocketError errorCode = SocketError.SocketError;
try
{
errorCode = SocketPal.ReceiveAsync(_handle, buffer, offset, size, socketFlags, asyncResult);
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Interop.Winsock.WSARecv returns:{errorCode} returning AsyncResult:{asyncResult}");
}
finally
{
errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
}
// Throw an appropriate SocketException if the native call fails synchronously.
if (errorCode != SocketError.Success)
{
// TODO: https://github.com/dotnet/corefx/issues/5426
// NetEventSource.Fail(this, "GetLastWin32Error() returned zero.");
// Update the internal state of this socket according to the error before throwing.
UpdateStatusAfterSocketError(errorCode);
var socketException = new SocketException((int)errorCode);
if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
asyncResult.InvokeCallback(new SocketException((int)errorCode));
}
#if DEBUG
else
{
_lastReceiveHandle = lastHandle;
_lastReceiveThread = Environment.CurrentManagedThreadId;
_lastReceiveTick = Environment.TickCount;
}
#endif
return errorCode;
}