public bool SendPacketsAsync(SocketAsyncEventArgs e)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, e);
bool retval;
// Throw if socket disposed
if (CleanedUp)
{
throw new ObjectDisposedException(GetType().FullName);
}
if (e == null)
{
throw new ArgumentNullException(nameof(e));
}
if (e.SendPacketsElements == null)
{
throw new ArgumentNullException("e.SendPacketsElements");
}
if (!Connected)
{
throw new NotSupportedException(SR.net_notconnected);
}
// Prepare for the native call.
e.StartOperationCommon(this);
e.StartOperationSendPackets();
// Make the native call.
SocketError socketError;
Debug.Assert(e.SendPacketsDescriptorCount != null);
if (e.SendPacketsDescriptorCount > 0)
{
try
{
socketError = e.DoOperationSendPackets(this, _handle);
}
catch (Exception)
{
// Clear in-use flag on event args object.
e.Complete();
throw;
}
// Handle completion when completion port is not posted.
if (socketError != SocketError.Success && socketError != SocketError.IOPending)
{
e.FinishOperationSyncFailure(socketError, 0, SocketFlags.None);
retval = false;
}
else
{
retval = true;
}
}
else
{
// No buffers or files to send.
e.FinishOperationSuccess(SocketError.Success, 0, SocketFlags.None);
retval = false;
}
if (NetEventSource.IsEnabled) NetEventSource.Exit(this, retval);
return retval;
}