Skip to content

Commit

Permalink
Support calling ConnectAsync for connectionless protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds committed Jan 30, 2020
1 parent f1b19a7 commit 6404854
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3779,7 +3779,15 @@ private bool ConnectAsync(SocketAsyncEventArgs e, bool userSocket)
SocketError socketError = SocketError.Success;
try
{
socketError = e.DoOperationConnect(this, _handle);
if (CanUseConnectEx(endPointSnapshot))
{
socketError = e.DoOperationConnectEx(this, _handle);
}
else
{
// For connectionless protocols, Connect is not an I/O call.
socketError = e.DoOperationConnect(this, _handle);
}
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ private void ConnectCompletionCallback(SocketError socketError)
CompletionCallback(0, SocketFlags.None, socketError);
}

internal unsafe SocketError DoOperationConnectEx(Socket socket, SafeSocketHandle handle)
=> DoOperationConnect(socket, handle);

internal unsafe SocketError DoOperationConnect(Socket socket, SafeSocketHandle handle)
{
SocketError socketError = handle.AsyncContext.ConnectAsync(_socketAddress.Buffer, _socketAddress.Size, ConnectCompletionCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ internal unsafe SocketError DoOperationAccept(Socket socket, SafeSocketHandle ha
}

internal unsafe SocketError DoOperationConnect(Socket socket, SafeSocketHandle handle)
{
// Called for connectionless protocols.
SocketError socketError = SocketPal.Connect(handle, _socketAddress.Buffer, _socketAddress.Size);
FinishOperationSync(socketError, 0, SocketFlags.None);
Debug.Assert(socketError != socketError.IOPending);
return socketError;
}

internal unsafe SocketError DoOperationConnectEx(Socket socket, SafeSocketHandle handle)
{
// ConnectEx uses a sockaddr buffer containing the remote address to which to connect.
// It can also optionally take a single buffer of data to send after the connection is complete.
Expand Down

0 comments on commit 6404854

Please sign in to comment.