Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ DnsConnectAsync()

bool System.Net.Sockets.SocketAsyncEventArgs.DnsConnectAsync ( DnsEndPoint endPoint,
SocketType socketType,
ProtocolType protocolType )
inlinepackageinherited

Definition at line 704 of file SocketAsyncEventArgs.cs.

705 {
707 Task<IPAddress[]> hostAddressesAsync = Dns.GetHostAddressesAsync(endPoint.Host, endPoint.AddressFamily, cancellationToken2);
708 MultiConnectSocketAsyncEventArgs multiConnectSocketAsyncEventArgs = new MultiConnectSocketAsyncEventArgs();
709 multiConnectSocketAsyncEventArgs.CopyBufferFrom(this);
711 return multiConnectSocketAsyncEventArgs.ReachedCoordinationPointFirst();
712 async Task Core(MultiConnectSocketAsyncEventArgs internalArgs, Task<IPAddress[]> addressesTask, int port, SocketType socketType, ProtocolType protocolType, CancellationToken cancellationToken)
713 {
714 Socket tempSocketIPv4 = null;
715 Socket tempSocketIPv5 = null;
716 Exception caughtException = null;
717 try
718 {
719 SocketError lastError = SocketError.NoData;
720 IPAddress[] array = await addressesTask.ConfigureAwait(continueOnCapturedContext: false);
721 foreach (IPAddress iPAddress in array)
722 {
723 Socket socket = null;
724 if (_currentSocket != null)
725 {
726 if (!_currentSocket.CanTryAddressFamily(iPAddress.AddressFamily))
727 {
728 continue;
729 }
731 }
732 else
733 {
734 if (iPAddress.AddressFamily == AddressFamily.InterNetworkV6)
735 {
737 if (socket2 == null)
738 {
740 tempSocketIPv5 = (socket3 = (Socket.OSSupportsIPv6 ? new Socket(AddressFamily.InterNetworkV6, socketType, protocolType) : null));
742 }
743 socket = socket2;
744 if (socket != null && iPAddress.IsIPv4MappedToIPv6)
745 {
746 socket.DualMode = true;
747 }
748 }
749 else if (iPAddress.AddressFamily == AddressFamily.InterNetwork)
750 {
752 if (socket4 == null)
753 {
755 tempSocketIPv4 = (socket3 = (Socket.OSSupportsIPv4 ? new Socket(AddressFamily.InterNetwork, socketType, protocolType) : null));
757 }
758 socket = socket4;
759 }
760 if (socket == null)
761 {
762 continue;
763 }
764 }
765 socket.ReplaceHandleIfNecessaryAfterFailedConnect();
766 if (internalArgs.RemoteEndPoint is IPEndPoint iPEndPoint)
767 {
768 iPEndPoint.Address = iPAddress;
769 }
770 else
771 {
772 internalArgs.RemoteEndPoint = new IPEndPoint(iPAddress, port);
773 }
774 if (socket.ConnectAsync(internalArgs))
775 {
776 using (cancellationToken.UnsafeRegister(delegate(object s)
777 {
778 Socket.CancelConnectAsync((SocketAsyncEventArgs)s);
779 }, internalArgs))
780 {
782 }
783 }
784 if (internalArgs.SocketError == SocketError.Success)
785 {
786 return;
787 }
788 if (cancellationToken.IsCancellationRequested)
789 {
790 throw new SocketException(995);
791 }
792 lastError = internalArgs.SocketError;
793 internalArgs.Reset();
794 }
795 caughtException = (Exception)(object)new SocketException((int)lastError);
796 }
797 catch (ObjectDisposedException)
798 {
799 caughtException = (Exception)(object)new SocketException(995);
800 }
801 catch (Exception ex2)
802 {
804 }
805 finally
806 {
807 if (tempSocketIPv4 != null && !tempSocketIPv4.Connected)
808 {
809 tempSocketIPv4.Dispose();
810 }
811 if (tempSocketIPv5 != null && !tempSocketIPv5.Connected)
812 {
813 tempSocketIPv5.Dispose();
814 }
815 if (_currentSocket != null && ((!_userSocket && !_currentSocket.Connected) || caughtException is OperationCanceledException || caughtException is SocketException { SocketErrorCode: SocketError.OperationAborted }))
816 {
818 }
819 if (caughtException != null)
820 {
821 SetResults(caughtException, 0, SocketFlags.None);
823 }
824 else
825 {
826 SetResults(SocketError.Success, internalArgs.BytesTransferred, internalArgs.SocketFlags);
827 _connectSocket = (_currentSocket = internalArgs.ConnectSocket);
828 }
829 if (SocketsTelemetry.Log.IsEnabled())
830 {
831 LogBytesTransferEvents(_connectSocket?.SocketType, SocketAsyncOperation.Connect, internalArgs.BytesTransferred);
832 }
833 Complete();
834 internalArgs.Dispose();
835 if (!internalArgs.ReachedCoordinationPointFirst())
836 {
837 OnCompleted(this);
838 }
839 }
840 }
841 }
static void LogBytesTransferEvents(SocketType? socketType, SocketAsyncOperation operation, int bytesTransferred)
void SetResults(SocketError socketError, int bytesTransferred, SocketFlags flags)
virtual void OnCompleted(SocketAsyncEventArgs e)
virtual void Dispose(bool disposing)
Definition Socket.cs:3294
void Connect(EndPoint remoteEP)
Definition Socket.cs:1206
void UpdateStatusAfterSocketError(SocketException socketException)
Definition Socket.cs:3726
bool CanTryAddressFamily(AddressFamily family)
Definition Socket.cs:1159
ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext)
Definition ValueTask.cs:312

References System.Net.Sockets.SocketAsyncEventArgs._connectSocket, System.Net.Sockets.SocketAsyncEventArgs._currentSocket, System.Net.Sockets.SocketAsyncEventArgs._multipleConnectCancellation, System.Net.Sockets.SocketAsyncEventArgs._socketError, System.Net.Sockets.SocketAsyncEventArgs._userSocket, System.array, System.Net.Sockets.Socket.CancelConnectAsync(), System.cancellationToken, System.Net.Sockets.Socket.CanTryAddressFamily(), System.Net.Sockets.SocketAsyncEventArgs.Complete(), System.Threading.Tasks.ValueTask< TResult >.ConfigureAwait(), System.Net.Sockets.Socket.Connect(), System.Net.Sockets.Socket.Connected, System.Net.Sockets.Socket.Dispose(), System.Net.Dns.GetHostAddressesAsync(), System.Net.Sockets.SocketsTelemetry.Log, System.Net.Sockets.SocketAsyncEventArgs.LogBytesTransferEvents(), System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(), System.s, System.Net.Sockets.SocketAsyncEventArgs.SetResults(), System.Net.Sockets.Socket, System.Threading.CancellationTokenSource.Token, and System.Net.Sockets.Socket.UpdateStatusAfterSocketError().

Referenced by System.Net.Sockets.Socket.ConnectAsync(), and System.Net.Sockets.Socket.ConnectAsync().