File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
src/libraries/System.Net.Sockets Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1168,6 +1168,13 @@ private unsafe SocketError FinishOperationConnect()
11681168 {
11691169 try
11701170 {
1171+ if ( _currentSocket ! . SocketType != SocketType . Stream )
1172+ {
1173+ // With connectionless sockets, regular connect is used instead of ConnectEx,
1174+ // attempting to set SO_UPDATE_CONNECT_CONTEXT will result in an error.
1175+ return SocketError . Success ;
1176+ }
1177+
11711178 // Update the socket context.
11721179 SocketError socketError = Interop . Winsock . setsockopt (
11731180 _currentSocket ! . SafeHandle ,
Original file line number Diff line number Diff line change 22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5+ using System . IO ;
56using System . Threading ;
67using System . Threading . Tasks ;
78using Xunit ;
@@ -30,6 +31,18 @@ public async Task Connect_Success(IPAddress listenAt)
3031 }
3132 }
3233
34+ [ Theory ]
35+ [ MemberData ( nameof ( Loopbacks ) ) ]
36+ public async Task Connect_Udp_Success ( IPAddress listenAt )
37+ {
38+ using Socket listener = new Socket ( listenAt . AddressFamily , SocketType . Dgram , ProtocolType . Udp ) ;
39+ using Socket client = new Socket ( listenAt . AddressFamily , SocketType . Dgram , ProtocolType . Udp ) ;
40+ listener . Bind ( new IPEndPoint ( listenAt , 0 ) ) ;
41+
42+ await ConnectAsync ( client , new IPEndPoint ( listenAt , ( ( IPEndPoint ) listener . LocalEndPoint ) . Port ) ) ;
43+ Assert . True ( client . Connected ) ;
44+ }
45+
3346 [ OuterLoop ]
3447 [ Theory ]
3548 [ MemberData ( nameof ( Loopbacks ) ) ]
You can’t perform that action at this time.
0 commit comments