本文整理汇总了C#中MultipleAddressConnectAsyncResult.StartPostingAsyncOp方法的典型用法代码示例。如果您正苦于以下问题:C# MultipleAddressConnectAsyncResult.StartPostingAsyncOp方法的具体用法?C# MultipleAddressConnectAsyncResult.StartPostingAsyncOp怎么用?C# MultipleAddressConnectAsyncResult.StartPostingAsyncOp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultipleAddressConnectAsyncResult
的用法示例。
在下文中一共展示了MultipleAddressConnectAsyncResult.StartPostingAsyncOp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginConnect
internal IAsyncResult BeginConnect(IPAddress[] addresses, int port, AsyncCallback requestCallback, object state)
{
if (s_loggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "BeginConnect", addresses);
}
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (addresses == null)
{
throw new ArgumentNullException("addresses");
}
if (addresses.Length == 0)
{
throw new ArgumentException(SR.net_invalidAddressList, "addresses");
}
if (!TcpValidationHelpers.ValidatePortNumber(port))
{
throw new ArgumentOutOfRangeException("port");
}
if (_addressFamily != AddressFamily.InterNetwork && _addressFamily != AddressFamily.InterNetworkV6)
{
throw new NotSupportedException(SR.net_invalidversion);
}
if (_isListening)
{
throw new InvalidOperationException(SR.net_sockets_mustnotlisten);
}
// Set up the result to capture the context. No need for a lock.
MultipleAddressConnectAsyncResult result = new MultipleAddressConnectAsyncResult(addresses, port, this, state, requestCallback);
result.StartPostingAsyncOp(false);
if (DoMultipleAddressConnectCallback(PostOneBeginConnect(result), result))
{
// If the call completes synchronously, invoke the callback from here.
result.InvokeCallback();
}
// Finished posting async op. Possibly will call callback.
result.FinishPostingAsyncOp(ref Caches.ConnectClosureCache);
if (s_loggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "BeginConnect", result);
}
return result;
}
示例2: BeginConnect
public IAsyncResult BeginConnect(IPAddress[] addresses, int port, AsyncCallback requestCallback, object state)
{
if (s_LoggingEnabled)
{
Logging.Enter(Logging.Sockets, this, "BeginConnect", addresses);
}
if (this.CleanedUp)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (addresses == null)
{
throw new ArgumentNullException("addresses");
}
if (addresses.Length == 0)
{
throw new ArgumentException(SR.GetString("net_invalidAddressList"), "addresses");
}
if (!ValidationHelper.ValidateTcpPort(port))
{
throw new ArgumentOutOfRangeException("port");
}
if ((this.addressFamily != System.Net.Sockets.AddressFamily.InterNetwork) && (this.addressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6))
{
throw new NotSupportedException(SR.GetString("net_invalidversion"));
}
if (this.isListening)
{
throw new InvalidOperationException(SR.GetString("net_sockets_mustnotlisten"));
}
MultipleAddressConnectAsyncResult context = new MultipleAddressConnectAsyncResult(addresses, port, this, state, requestCallback);
context.StartPostingAsyncOp(false);
if (DoMultipleAddressConnectCallback(PostOneBeginConnect(context), context))
{
context.InvokeCallback();
}
context.FinishPostingAsyncOp(ref this.Caches.ConnectClosureCache);
if (s_LoggingEnabled)
{
Logging.Exit(Logging.Sockets, this, "BeginConnect", context);
}
return context;
}
示例3: BeginConnect
public IAsyncResult BeginConnect(string host, int port, AsyncCallback requestCallback, object state)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, host);
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (host == null)
{
throw new ArgumentNullException(nameof(host));
}
if (!TcpValidationHelpers.ValidatePortNumber(port))
{
throw new ArgumentOutOfRangeException(nameof(port));
}
if (_addressFamily != AddressFamily.InterNetwork && _addressFamily != AddressFamily.InterNetworkV6)
{
throw new NotSupportedException(SR.net_invalidversion);
}
if (_isListening)
{
throw new InvalidOperationException(SR.net_sockets_mustnotlisten);
}
IPAddress parsedAddress;
if (IPAddress.TryParse(host, out parsedAddress))
{
IAsyncResult r = BeginConnect(parsedAddress, port, requestCallback, state);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this, r);
return r;
}
ThrowIfNotSupportsMultipleConnectAttempts();
// Here, want to flow the context. No need to lock.
MultipleAddressConnectAsyncResult result = new MultipleAddressConnectAsyncResult(null, port, this, state, requestCallback);
result.StartPostingAsyncOp(false);
IAsyncResult dnsResult = DnsAPMExtensions.BeginGetHostAddresses(host, new AsyncCallback(DnsCallback), result);
if (dnsResult.CompletedSynchronously)
{
if (DoDnsCallback(dnsResult, result))
{
result.InvokeCallback();
}
}
// Done posting.
result.FinishPostingAsyncOp(ref Caches.ConnectClosureCache);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this, result);
return result;
}