本文整理汇总了C#中System.Net.Sockets.OverlappedAsyncResult类的典型用法代码示例。如果您正苦于以下问题:C# OverlappedAsyncResult类的具体用法?C# OverlappedAsyncResult怎么用?C# OverlappedAsyncResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OverlappedAsyncResult类属于System.Net.Sockets命名空间,在下文中一共展示了OverlappedAsyncResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SendToAsync
public static unsafe SocketError SendToAsync(SafeCloseSocket handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, Internals.SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
{
// Set up asyncResult for overlapped WSASendTo.
// This call will use completion ports.
asyncResult.SetUnmanagedStructures(buffer, offset, count, socketAddress, false /* don't pin RemoteEP*/);
int bytesTransferred;
SocketError errorCode = Interop.Winsock.WSASendTo(
handle,
ref asyncResult._singleBuffer,
1, // There is only ever 1 buffer being sent.
out bytesTransferred,
socketFlags,
asyncResult.GetSocketAddressPtr(),
asyncResult.SocketAddress.Size,
asyncResult.OverlappedHandle,
IntPtr.Zero);
if (errorCode != SocketError.Success)
{
errorCode = GetLastSocketError();
}
return errorCode;
}
开发者ID:vbouret,项目名称:corefx,代码行数:25,代码来源:SocketPal.Windows.cs
示例2: BeginReceive
internal IAsyncResult BeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
{
if (s_loggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "BeginReceive", "");
}
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
// Validate input parameters.
if (buffers == null)
{
throw new ArgumentNullException("buffers");
}
if (buffers.Count == 0)
{
throw new ArgumentException(SR.Format(SR.net_sockets_zerolist, "buffers"), "buffers");
}
// We need to flow the context here. But we don't need to lock the context - we don't use it until the callback.
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
// Run the receive with this asyncResult.
errorCode = DoBeginReceive(buffers, socketFlags, asyncResult);
if (errorCode != SocketError.Success && errorCode != SocketError.IOPending)
{
asyncResult = null;
}
else
{
// We're not throwing, so finish the async op posting code so we can return to the user.
// If the operation already finished, the callback will be called from here.
asyncResult.FinishPostingAsyncOp(ref Caches.ReceiveClosureCache);
}
if (s_loggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "BeginReceive", asyncResult);
}
return asyncResult;
}
开发者ID:ReedKimble,项目名称:corefx,代码行数:47,代码来源:Socket.cs
示例3: BeginReceiveFrom
// Routine Description:
//
// BeginReceiveFrom - Async implimentation of RecvFrom call,
//
// Called when we want to start an async receive.
// We kick off the receive, and if it completes synchronously we'll
// call the callback. Otherwise we'll return an IASyncResult, which
// the caller can use to wait on or retrieve the final status, as needed.
//
// Uses Winsock 2 overlapped I/O.
//
// Arguments:
//
// ReadBuffer - status line that we wish to parse
// Index - Offset into ReadBuffer to begin reading from
// Request - Size of Buffer to recv
// Flags - Additonal Flags that may be passed to the underlying winsock call
// remoteEP - EndPoint that are to receive from
// Callback - Delegate function that holds callback, called on completeion of I/O
// State - State used to track callback, set by caller, not required
//
// Return Value:
//
// IAsyncResult - Async result used to retreive result
internal IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback callback, object state)
{
if (s_loggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "BeginReceiveFrom", "");
}
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
// Validate input parameters.
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if (remoteEP == null)
{
throw new ArgumentNullException("remoteEP");
}
if (!CanTryAddressFamily(remoteEP.AddressFamily))
{
throw new ArgumentException(SR.Format(SR.net_InvalidEndPointAddressFamily, remoteEP.AddressFamily, _addressFamily), "remoteEP");
}
if (offset < 0 || offset > buffer.Length)
{
throw new ArgumentOutOfRangeException("offset");
}
if (size < 0 || size > buffer.Length - offset)
{
throw new ArgumentOutOfRangeException("size");
}
if (_rightEndPoint == null)
{
throw new InvalidOperationException(SR.net_sockets_mustbind);
}
// We don't do a CAS demand here because the contents of remoteEP aren't used by
// WSARecvFrom; all that matters is that we generate a unique-to-this-call SocketAddress
// with the right address family
Internals.SocketAddress socketAddress = SnapshotAndSerialize(ref remoteEP);
// Set up the result and set it to collect the context.
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
// Start the ReceiveFrom.
DoBeginReceiveFrom(buffer, offset, size, socketFlags, remoteEP, socketAddress, asyncResult);
// Capture the context, maybe call the callback, and return.
asyncResult.FinishPostingAsyncOp(ref Caches.ReceiveClosureCache);
if (asyncResult.CompletedSynchronously && !asyncResult.SocketAddressOriginal.Equals(asyncResult.SocketAddress))
{
try
{
remoteEP = remoteEP.Create(asyncResult.SocketAddress);
}
catch
{
}
}
if (s_loggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "BeginReceiveFrom", asyncResult);
}
return asyncResult;
}
开发者ID:ReedKimble,项目名称:corefx,代码行数:95,代码来源:Socket.cs
示例4: DoBeginSend
private SocketError DoBeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
GlobalLog.Print("Socket#" + Logging.HashString(this) + "::BeginSend() SRC:" + Logging.ObjectToString(LocalEndPoint) + " DST:" + Logging.ObjectToString(RemoteEndPoint) + " buffers:" + buffers);
// 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
{
GlobalLog.Print("BeginSend: asyncResult:" + Logging.HashString(asyncResult));
errorCode = SocketPal.SendAsync(_handle, buffers, socketFlags, asyncResult);
GlobalLog.Print("Socket#" + Logging.HashString(this) + "::BeginSend() Interop.Winsock.WSASend 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)
{
UpdateStatusAfterSocketError(errorCode);
if (s_loggingEnabled)
{
Logging.Exception(Logging.Sockets, this, "BeginSend", new SocketException((int)errorCode));
}
}
return errorCode;
}
开发者ID:ReedKimble,项目名称:corefx,代码行数:31,代码来源:Socket.cs
示例5: ReceiveAsync
public static SocketError ReceiveAsync(SafeCloseSocket handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
return handle.AsyncContext.ReceiveAsync(buffer, offset, count, socketFlags, asyncResult.CompletionCallback);
}
开发者ID:jemmy655,项目名称:corefx,代码行数:4,代码来源:SocketPal.Unix.cs
示例6: ReceiveFromAsync
public static SocketError ReceiveFromAsync(SafeCloseSocket handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, Internals.SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
{
asyncResult.SocketAddress = socketAddress;
return handle.AsyncContext.ReceiveFromAsync(buffer, offset, count, socketFlags, socketAddress.Buffer, socketAddress.InternalSize, asyncResult.CompletionCallback);
}
开发者ID:jemmy655,项目名称:corefx,代码行数:6,代码来源:SocketPal.Unix.cs
示例7: DoBeginReceive
private SocketError DoBeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.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);
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::BeginReceive() Interop.Winsock.WSARecv returns:" + errorCode.ToString() + " returning AsyncResult:" + LoggingHash.HashString(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
//if (GlobalLog.IsEnabled)
//{
// GlobalLog.AssertFormat("Socket#{0}::DoBeginReceive()|GetLastWin32Error() returned zero.", LoggingHash.HashString(this));
//}
// Update the internal state of this socket according to the error before throwing.
UpdateStatusAfterSocketError(errorCode);
if (s_loggingEnabled)
{
NetEventSource.Exception(NetEventSource.ComponentType.Socket, this, nameof(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;
}
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:55,代码来源:Socket.cs
示例8: DoBeginSend
private SocketError DoBeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::BeginSend() SRC:" + ValidationHelper.ToString(LocalEndPoint) + " DST:" + ValidationHelper.ToString(RemoteEndPoint) + " buffers:" + buffers);
// 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 WSASend.
// This call will use completion ports on WinNT and Overlapped IO on Win9x.
asyncResult.SetUnmanagedStructures(buffers, ref Caches.SendOverlappedCache);
GlobalLog.Print("BeginSend: asyncResult:" + ValidationHelper.HashString(asyncResult));
// This can throw ObjectDisposedException.
int bytesTransferred;
errorCode = UnsafeNclNativeMethods.OSSOCK.WSASend(
m_Handle,
asyncResult.m_WSABuffers,
asyncResult.m_WSABuffers.Length,
out bytesTransferred,
socketFlags,
asyncResult.OverlappedHandle,
IntPtr.Zero);
if (errorCode!=SocketError.Success) {
errorCode = (SocketError)Marshal.GetLastWin32Error();
}
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::BeginSend() UnsafeNclNativeMethods.OSSOCK.WSASend returns:" + errorCode.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)
{
asyncResult.ExtractCache(ref Caches.SendOverlappedCache);
UpdateStatusAfterSocketError(errorCode);
if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "BeginSend", new SocketException(errorCode));
}
return errorCode;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:49,代码来源:Socket.cs
示例9: DoBeginSend
private SocketError DoBeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::BeginSend() SRC:" + LoggingHash.ObjectToString(LocalEndPoint) + " DST:" + LoggingHash.ObjectToString(RemoteEndPoint) + " size:" + size.ToString());
}
// 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
{
// Get the Send going.
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("BeginSend: asyncResult:" + LoggingHash.HashString(asyncResult) + " size:" + size.ToString());
}
errorCode = SocketPal.SendAsync(_handle, buffer, offset, size, socketFlags, asyncResult);
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::BeginSend() Interop.Winsock.WSASend returns:" + errorCode.ToString() + " size:" + size.ToString() + " returning AsyncResult:" + LoggingHash.HashString(asyncResult));
}
}
finally
{
errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
}
// Throw an appropriate SocketException if the native call fails synchronously.
if (errorCode != SocketError.Success)
{
UpdateStatusAfterSocketError(errorCode);
if (s_loggingEnabled)
{
NetEventSource.Exception(NetEventSource.ComponentType.Socket, this, nameof(BeginSend), new SocketException((int)errorCode));
}
}
return errorCode;
}
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:41,代码来源:Socket.cs
示例10: DoBeginSendTo
private void DoBeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint endPointSnapshot, Internals.SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
{
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::DoBeginSendTo() size:" + size.ToString());
}
EndPoint oldEndPoint = _rightEndPoint;
// 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
{
if (_rightEndPoint == null)
{
_rightEndPoint = endPointSnapshot;
}
errorCode = SocketPal.SendToAsync(_handle, buffer, offset, size, socketFlags, socketAddress, asyncResult);
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::DoBeginSendTo() Interop.Winsock.WSASend returns:" + errorCode.ToString() + " size:" + size + " returning AsyncResult:" + LoggingHash.HashString(asyncResult));
}
}
catch (ObjectDisposedException)
{
_rightEndPoint = oldEndPoint;
throw;
}
finally
{
errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
}
// Throw an appropriate SocketException if the native call fails synchronously.
if (errorCode != SocketError.Success)
{
// Update the internal state of this socket according to the error before throwing.
_rightEndPoint = oldEndPoint;
SocketException socketException = new SocketException((int)errorCode);
UpdateStatusAfterSocketError(socketException);
if (s_loggingEnabled)
{
NetEventSource.Exception(NetEventSource.ComponentType.Socket, this, nameof(BeginSendTo), socketException);
}
throw socketException;
}
if (GlobalLog.IsEnabled)
{
GlobalLog.Print("Socket#" + LoggingHash.HashString(this) + "::DoBeginSendTo() size:" + size.ToString() + " returning AsyncResult:" + LoggingHash.HashString(asyncResult));
}
}
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:55,代码来源:Socket.cs
示例11: ReceiveFromAsync
public static unsafe SocketError ReceiveFromAsync(SafeCloseSocket handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, Internals.SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
{
// Set up asyncResult for overlapped WSARecvFrom.
// This call will use completion ports on WinNT and Overlapped IO on Win9x.
asyncResult.SetUnmanagedStructures(buffer, offset, count, socketAddress, true);
int bytesTransferred;
SocketError errorCode = Interop.Winsock.WSARecvFrom(
handle,
ref asyncResult._singleBuffer,
1,
out bytesTransferred,
ref socketFlags,
asyncResult.GetSocketAddressPtr(),
asyncResult.GetSocketAddressSizePtr(),
asyncResult.OverlappedHandle,
IntPtr.Zero);
if (errorCode != SocketError.Success)
{
errorCode = GetLastSocketError();
}
return errorCode;
}
开发者ID:vbouret,项目名称:corefx,代码行数:25,代码来源:SocketPal.Windows.cs
示例12: ReceiveAsync
public static unsafe SocketError ReceiveAsync(SafeCloseSocket handle, IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
// Set up asyncResult for overlapped WSASend.
// This call will use completion ports.
asyncResult.SetUnmanagedStructures(buffers);
// This can throw ObjectDisposedException.
int bytesTransferred;
SocketError errorCode = Interop.Winsock.WSARecv(
handle,
asyncResult._wsaBuffers,
asyncResult._wsaBuffers.Length,
out bytesTransferred,
ref socketFlags,
asyncResult.OverlappedHandle,
IntPtr.Zero);
if (errorCode != SocketError.Success)
{
errorCode = GetLastSocketError();
}
return errorCode;
}
开发者ID:vbouret,项目名称:corefx,代码行数:24,代码来源:SocketPal.Windows.cs
示例13: SendAsync
public static SocketError SendAsync(SafeCloseSocket handle, BufferOffsetSize[] buffers, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
return handle.AsyncContext.SendAsync(new BufferList(buffers), GetPlatformSocketFlags(socketFlags), asyncResult.CompletionCallback);
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:4,代码来源:SocketPal.Unix.cs
示例14: DoBeginReceive
private SocketError DoBeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
{
#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 WSASend.
// This call will use completion ports on WinNT and Overlapped IO on Win9x.
asyncResult.SetUnmanagedStructures(buffers, ref Caches.ReceiveOverlappedCache);
// This can throw ObjectDisposedException.
int bytesTransferred;
errorCode = UnsafeNclNativeMethods.OSSOCK.WSARecv(
m_Handle,
asyncResult.m_WSABuffers,
asyncResult.m_WSABuffers.Length,
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) + "::DoBeginReceive() UnsafeNclNativeMethods.OSSOCK.WSARecv returns:" + errorCode.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));
}
#if DEBUG
else
{
m_LastReceiveHandle = lastHandle;
m_LastReceiveThread = Thread.CurrentThread.ManagedThreadId;
m_LastReceiveTick = Environment.TickCount;
}
#endif
return errorCode;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:59,代码来源:Socket.cs
示例15: SendToAsync
public static SocketError SendToAsync(SafeCloseSocket handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, Internals.SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
{
asyncResult.SocketAddress = socketAddress;
return handle.AsyncContext.SendToAsync(buffer, offset, count, GetPlatformSocketFlags(socketFlags), socketAddress.Buffer, socketAddress.Size, asyncResult.CompletionCallback);
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:6,代码来源:SocketPal.Unix.cs
示例16: DoBeginReceiveFrom
private void DoBeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint endPointSnapshot, SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
{
EndPoint oldEndPoint = m_RightEndPoint;
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginReceiveFrom() size:" + size.ToString());
// 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 WSARecvFrom.
// This call will use completion ports on WinNT and Overlapped IO on Win9x.
asyncResult.SetUnmanagedStructures(buffer, offset, size, socketAddress, true /* pin remoteEP*/, ref Caches.ReceiveOverlappedCache);
// save a copy of the original EndPoint in the asyncResult
asyncResult.SocketAddressOriginal = endPointSnapshot.Serialize();
if (m_RightEndPoint == null) {
m_RightEndPoint = endPointSnapshot;
}
int bytesTransferred;
errorCode = UnsafeNclNativeMethods.OSSOCK.WSARecvFrom(
m_Handle,
ref asyncResult.m_SingleBuffer,
1,
out bytesTransferred,
ref socketFlags,
asyncResult.GetSocketAddressPtr(),
asyncResult.GetSocketAddressSizePtr(),
asyncResult.OverlappedHandle,
IntPtr.Zero );
if (errorCode!=SocketError.Success) {
errorCode = (SocketError)Marshal.GetLastWin32Error();
}
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginReceiveFrom() UnsafeNclNativeMethods.OSSOCK.WSARecvFrom returns:" + errorCode.ToString() + " size:" + size.ToString() + " returning AsyncResult:" + ValidationHelper.HashString(asyncResult));
}
catch (ObjectDisposedException)
{
m_RightEndPoint = oldEndPoint;
throw;
}
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
//
m_RightEndPoint = oldEndPoint;
asyncResult.ExtractCache(ref Caches.ReceiveOverlappedCache);
SocketException socketException = new SocketException(errorCode);
UpdateStatusAfterSocketError(socketException);
if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "BeginReceiveFrom", socketException);
throw socketException;
}
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginReceiveFrom() size:" + size.ToString() + " returning AsyncResult:" + ValidationHelper.HashString(asyncResult));
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:66,代码来源:Socket.cs
示例17: BeginMultipleSend
internal IAsyncResult BeginMultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state) {
// Set up the async result and start the flow.
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
// Start the send.
DoBeginMultipleSend(buffers, socketFlags, asyncResult);
// Finish it up (capture, complete).
asyncResult.FinishPostingAsyncOp(ref Caches.SendClosureCache);
return asyncResult;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:12,代码来源:Socket.cs
示例18: UnsafeBeginSend
internal IAsyncResult UnsafeBeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state)
{
if (s_loggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "UnsafeBeginSend", "");
}
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
// No need to flow the context.
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
SocketError errorCode = DoBeginSend(buffer, offset, size, socketFlags, asyncResult);
if (errorCode != SocketError.Success && errorCode != SocketError.IOPending)
{
throw new SocketException((int)errorCode);
}
if (s_loggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "UnsafeBeginSend", asyncResult);
}
return asyncResult;
}
开发者ID:ReedKimble,项目名称:corefx,代码行数:27,代码来源:Socket.cs
示例19: UnsafeBeginMultipleSend
internal IAsyncResult UnsafeBeginMultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
{
// Unsafe - don't flow.
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
DoBeginMultipleSend(buffers, socketFlags, asyncResult);
return asyncResult;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:7,代码来源:Socket.cs
示例20: BeginSendTo
// Routine Description:
//
// BeginSendTo - Async implimentation of SendTo,
//
// This routine may go pending at which time,
// but any case the callback Delegate will be called upon completion
//
// Arguments:
//
// WriteBuffer - Buffer to transmit
// Index - Offset into WriteBuffer to begin sending from
// Size - Size of Buffer to transmit
// Flags - Specific Socket flags to pass to winsock
// remoteEP - EndPoint to transmit To
// Callback - Delegate function that holds callback, called on completeion of I/O
// State - State used to track callback, set by caller, not required
//
// Return Value:
//
// IAsyncResult - Async result used to retreive result
internal IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint remoteEP, AsyncCallback callback, object state)
{
if (s_loggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "BeginSendTo", "");
}
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
// Validate input parameters.
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if (remoteEP == null)
{
throw new ArgumentNullException("remoteEP");
}
if (offset < 0 || offset > buffer.Length)
{
throw new ArgumentOutOfRangeException("offset");
}
if (size < 0 || size > buffer.Length - offset)
{
throw new ArgumentOutOfRangeException("size");
}
// This will check the permissions for connect.
EndPoint endPointSnapshot = remoteEP;
Internals.SocketAddress socketAddress = CheckCacheRemote(ref endPointSnapshot, false);
// Set up the async result and indicate to flow the context.
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
// Post the send.
DoBeginSendTo(buffer, offset, size, socketFlags, endPointSnapshot, socketAddress, asyncResult);
// Finish, possibly posting the callback. The callback won't be posted before this point is reached.
asyncResult.FinishPostingAsyncOp(ref Caches.SendClosureCache);
if (s_loggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "BeginSendTo", asyncResult);
}
return asyncResult;
}
开发者ID:ReedKimble,项目名称:corefx,代码行数:70,代码来源:Socket.cs
注:本文中的System.Net.Sockets.OverlappedAsyncResult类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论