本文整理汇总了C#中System.Net.Sockets.OverlappedAsyncResult.FinishPostingAsyncOp方法的典型用法代码示例。如果您正苦于以下问题:C# OverlappedAsyncResult.FinishPostingAsyncOp方法的具体用法?C# OverlappedAsyncResult.FinishPostingAsyncOp怎么用?C# OverlappedAsyncResult.FinishPostingAsyncOp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.OverlappedAsyncResult
的用法示例。
在下文中一共展示了OverlappedAsyncResult.FinishPostingAsyncOp方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: BeginMultipleSend
internal IAsyncResult BeginMultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
{
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
this.DoBeginMultipleSend(buffers, socketFlags, asyncResult);
asyncResult.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
return (IAsyncResult) asyncResult;
}
示例5: 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;
}
示例6: BeginSend
public IAsyncResult BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
{
if (Socket.s_LoggingEnabled)
Logging.Enter(Logging.Sockets, (object) this, "BeginSend", "");
if (this.CleanedUp)
throw new ObjectDisposedException(this.GetType().FullName);
if (buffers == null)
throw new ArgumentNullException("buffers");
if (buffers.Count == 0)
{
throw new ArgumentException(SR.GetString("net_sockets_zerolist", new object[1]
{
(object) "buffers"
}), "buffers");
}
else
{
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
errorCode = this.DoBeginSend(buffers, socketFlags, asyncResult);
asyncResult.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
if (errorCode != SocketError.Success && errorCode != SocketError.IOPending)
asyncResult = (OverlappedAsyncResult) null;
if (Socket.s_LoggingEnabled)
Logging.Exit(Logging.Sockets, (object) this, "BeginSend", (object) asyncResult);
return (IAsyncResult) asyncResult;
}
}
示例7: BeginSendTo
public IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint remoteEP, AsyncCallback callback, object state)
{
if (Socket.s_LoggingEnabled)
Logging.Enter(Logging.Sockets, (object) this, "BeginSendTo", "");
if (this.CleanedUp)
throw new ObjectDisposedException(this.GetType().FullName);
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");
EndPoint remoteEP1 = remoteEP;
SocketAddress socketAddress = this.CheckCacheRemote(ref remoteEP1, false);
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
this.DoBeginSendTo(buffer, offset, size, socketFlags, remoteEP1, socketAddress, asyncResult);
asyncResult.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
if (Socket.s_LoggingEnabled)
Logging.Exit(Logging.Sockets, (object) this, "BeginSendTo", (object) asyncResult);
return (IAsyncResult) asyncResult;
}
示例8: BeginReceiveFrom
public IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback callback, object state)
{
if (Socket.s_LoggingEnabled)
Logging.Enter(Logging.Sockets, (object) this, "BeginReceiveFrom", "");
if (this.CleanedUp)
throw new ObjectDisposedException(this.GetType().FullName);
if (buffer == null)
throw new ArgumentNullException("buffer");
if (remoteEP == null)
throw new ArgumentNullException("remoteEP");
if (!this.CanTryAddressFamily(remoteEP.AddressFamily))
{
throw new ArgumentException(SR.GetString("net_InvalidEndPointAddressFamily", (object) remoteEP.AddressFamily, (object) this.addressFamily), "remoteEP");
}
else
{
if (offset < 0 || offset > buffer.Length)
throw new ArgumentOutOfRangeException("offset");
if (size < 0 || size > buffer.Length - offset)
throw new ArgumentOutOfRangeException("size");
if (this.m_RightEndPoint == null)
throw new InvalidOperationException(SR.GetString("net_sockets_mustbind"));
SocketAddress socketAddress = this.SnapshotAndSerialize(ref remoteEP);
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
this.DoBeginReceiveFrom(buffer, offset, size, socketFlags, remoteEP, socketAddress, asyncResult);
asyncResult.FinishPostingAsyncOp(ref this.Caches.ReceiveClosureCache);
if (asyncResult.CompletedSynchronously)
{
if (!asyncResult.SocketAddressOriginal.Equals((object) asyncResult.SocketAddress))
{
try
{
remoteEP = remoteEP.Create(asyncResult.SocketAddress);
}
catch
{
}
}
}
if (Socket.s_LoggingEnabled)
Logging.Exit(Logging.Sockets, (object) this, "BeginReceiveFrom", (object) asyncResult);
return (IAsyncResult) asyncResult;
}
}
示例9: BeginReceiveFrom
public IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback callback, object state)
{
if (Logging.On) Logging.Enter(Logging.Sockets, this, "BeginReceiveFrom", "");
if (CleanedUp) {
throw new ObjectDisposedException(this.GetType().FullName);
}
//
// parameter validation
//
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");
}
if (m_RightEndPoint==null) {
throw new InvalidOperationException(SR.GetString(SR.net_sockets_mustbind));
}
// This will check the permissions for connect.
EndPoint endPointSnapshot = remoteEP;
SocketAddress socketAddress = CheckCacheRemote(ref endPointSnapshot, false);
// 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, endPointSnapshot, 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 = endPointSnapshot.Create(asyncResult.SocketAddress);
}
catch {
}
}
if(Logging.On)Logging.Exit(Logging.Sockets, this, "BeginReceiveFrom", asyncResult);
return asyncResult;
}
示例10: BeginReceive
public IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
{
if (s_LoggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "BeginReceive", "");
}
if (this.CleanedUp)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if ((offset < 0) || (offset > buffer.Length))
{
throw new ArgumentOutOfRangeException("offset");
}
if ((size < 0) || (size > (buffer.Length - offset)))
{
throw new ArgumentOutOfRangeException("size");
}
OverlappedAsyncResult asyncResult = new OverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
errorCode = this.DoBeginReceive(buffer, offset, size, socketFlags, asyncResult);
if ((errorCode != SocketError.Success) && (errorCode != SocketError.IOPending))
{
asyncResult = null;
}
else
{
asyncResult.FinishPostingAsyncOp(ref this.Caches.ReceiveClosureCache);
}
if (s_LoggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "BeginReceive", asyncResult);
}
return asyncResult;
}