public IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state) { // // parameter validation // if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "BeginConnect", remoteEP); if (CleanedUp) { throw new ObjectDisposedException(this.GetType().FullName); } if (remoteEP==null) { throw new ArgumentNullException("remoteEP"); } if (isListening) { throw new InvalidOperationException(SR.GetString(SR.net_sockets_mustnotlisten)); } DnsEndPoint dnsEP = remoteEP as DnsEndPoint; if (dnsEP != null) { if (dnsEP.AddressFamily != AddressFamily.Unspecified && !CanTryAddressFamily(dnsEP.AddressFamily)) { throw new NotSupportedException(SR.GetString(SR.net_invalidversion)); } return BeginConnect(dnsEP.Host, dnsEP.Port, callback, state); } if (CanUseConnectEx(remoteEP)) { return BeginConnectEx(remoteEP, true, callback, state); } // This will check the permissions for connect. EndPoint endPointSnapshot = remoteEP; SocketAddress socketAddress = CheckCacheRemote(ref endPointSnapshot, true); // Flow the context. No need to lock it since we don't use it until the callback. ConnectAsyncResult asyncResult = new ConnectAsyncResult(this, endPointSnapshot, state, callback); asyncResult.StartPostingAsyncOp(false); // Post the connect. DoBeginConnect(endPointSnapshot, socketAddress, asyncResult); // We didn't throw, so finish the posting op. This will call the callback if the operation already completed. asyncResult.FinishPostingAsyncOp(ref Caches.ConnectClosureCache); if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "BeginConnect", asyncResult); return asyncResult; }
internal IAsyncResult UnsafeBeginConnect(IPEndPoint remoteEP, AsyncCallback callback, object state) { if (CanUseConnectEx(remoteEP)) { return BeginConnectEx(remoteEP, false, callback, state); } EndPoint endPointSnapshot = remoteEP; var asyncResult = new ConnectAsyncResult(this, endPointSnapshot, state, callback); // For connectionless protocols, Connect is not an I/O call. Connect(remoteEP); asyncResult.FinishPostingAsyncOp(); // Synchronously complete the I/O and call the user's callback. asyncResult.InvokeCallback(); return asyncResult; }
public IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state) { if (Socket.s_LoggingEnabled) Logging.Enter(Logging.Sockets, (object) this, "BeginConnect", (object) remoteEP); if (this.CleanedUp) throw new ObjectDisposedException(this.GetType().FullName); if (remoteEP == null) throw new ArgumentNullException("remoteEP"); if (this.isListening) throw new InvalidOperationException(SR.GetString("net_sockets_mustnotlisten")); DnsEndPoint dnsEndPoint = remoteEP as DnsEndPoint; if (dnsEndPoint != null) { if (dnsEndPoint.AddressFamily != AddressFamily.Unspecified && !this.CanTryAddressFamily(dnsEndPoint.AddressFamily)) throw new NotSupportedException(SR.GetString("net_invalidversion")); else return this.BeginConnect(dnsEndPoint.Host, dnsEndPoint.Port, callback, state); } else { if (this.CanUseConnectEx(remoteEP)) return this.BeginConnectEx(remoteEP, true, callback, state); EndPoint remoteEP1 = remoteEP; SocketAddress socketAddress = this.CheckCacheRemote(ref remoteEP1, true); ConnectAsyncResult connectAsyncResult = new ConnectAsyncResult((object) this, remoteEP1, state, callback); connectAsyncResult.StartPostingAsyncOp(false); this.DoBeginConnect(remoteEP1, socketAddress, (LazyAsyncResult) connectAsyncResult); connectAsyncResult.FinishPostingAsyncOp(ref this.Caches.ConnectClosureCache); if (Socket.s_LoggingEnabled) Logging.Exit(Logging.Sockets, (object) this, "BeginConnect", (object) connectAsyncResult); return (IAsyncResult) connectAsyncResult; } }
public IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state) { if (s_LoggingEnabled) { Logging.Enter(Logging.Sockets, this, "BeginConnect", remoteEP); } if (this.CleanedUp) { throw new ObjectDisposedException(base.GetType().FullName); } if (remoteEP == null) { throw new ArgumentNullException("remoteEP"); } if (this.isListening) { throw new InvalidOperationException(SR.GetString("net_sockets_mustnotlisten")); } DnsEndPoint point = remoteEP as DnsEndPoint; if (point != null) { if ((point.AddressFamily != System.Net.Sockets.AddressFamily.Unspecified) && (point.AddressFamily != this.addressFamily)) { throw new NotSupportedException(SR.GetString("net_invalidversion")); } return this.BeginConnect(point.Host, point.Port, callback, state); } if (this.CanUseConnectEx(remoteEP)) { return this.BeginConnectEx(remoteEP, true, callback, state); } EndPoint point2 = remoteEP; SocketAddress socketAddress = this.CheckCacheRemote(ref point2, true); ConnectAsyncResult asyncResult = new ConnectAsyncResult(this, point2, state, callback); asyncResult.StartPostingAsyncOp(false); this.DoBeginConnect(point2, socketAddress, asyncResult); asyncResult.FinishPostingAsyncOp(ref this.Caches.ConnectClosureCache); if (s_LoggingEnabled) { Logging.Exit(Logging.Sockets, this, "BeginConnect", asyncResult); } return asyncResult; }