System.Net.Sockets.SocketAsyncEventArgs.DoOperationSendPackets C# (CSharp) Method

DoOperationSendPackets() private method

private DoOperationSendPackets ( Socket socket, SafeCloseSocket handle ) : SocketError
socket Socket
handle SafeCloseSocket
return SocketError
        internal SocketError DoOperationSendPackets(Socket socket, SafeCloseSocket handle)
        {
            PrepareIOCPOperation();

            bool result = socket.TransmitPackets(
                handle,
                _ptrSendPacketsDescriptor,
                _sendPacketsDescriptor.Length,
                _sendPacketsSendSize,
                _ptrNativeOverlapped);

            return result ? SocketError.Success : SocketPal.GetLastSocketError();
        }

Usage Example

Example #1
0
        public bool SendPacketsAsync(SocketAsyncEventArgs e)
        {
            bool retval;

            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "SendPacketsAsync", "");
            }

            // Throw if socket disposed
            if (CleanedUp)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            if (e == null)
            {
                throw new ArgumentNullException("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 (s_loggingEnabled)
            {
                Logging.Exit(Logging.Sockets, this, "SendPacketsAsync", retval);
            }

            return retval;
        }
SocketAsyncEventArgs