Example #1
0
        /// <summary>
        /// Send packet asynchronously
        /// </summary>
        /// <param name="packet">SNI packet</param>
        /// <param name="callback">Completion callback</param>
        /// <returns>SNI error code</returns>
        private uint InternalSendAsync(SNIPacket packet, SNIAsyncCallback callback)
        {
            SNIPacket encapsulatedPacket = null;

            lock (this)
            {
                if (_sequenceNumber >= _sendHighwater)
                {
                    return(TdsEnums.SNI_QUEUE_FULL);
                }

                encapsulatedPacket = GetSMUXEncapsulatedPacket(packet);

                if (callback != null)
                {
                    encapsulatedPacket.SetCompletionCallback(callback);
                }
                else
                {
                    encapsulatedPacket.SetCompletionCallback(HandleSendComplete);
                }

                return(_connection.SendAsync(encapsulatedPacket, callback));
            }
        }
Example #2
0
        /// <summary>
        /// Send control packet
        /// </summary>
        /// <param name="flags">SMUX header flags</param>
        /// <param name="async">true if packet should be sent asynchronously</param>
        private void SendControlPacket(SNISMUXFlags flags, bool async)
        {
            byte[] headerBytes = null;

            lock (this)
            {
                GetSMUXHeaderBytes(0, (byte)flags, ref headerBytes);
            }

            SNIPacket packet = new SNIPacket(null);

            packet.SetData(headerBytes, SNISMUXHeader.HEADER_LENGTH);

            if (async)
            {
                _connection.SendAsync(packet, (sentPacket, error) => { });
            }
            else
            {
                _connection.Send(packet);
            }
        }
Example #3
0
        /// <summary>
        /// Send control packet
        /// </summary>
        /// <param name="flags">SMUX header flags</param>
        /// <param name="async">true if packet should be sent asynchronously</param>
        /// <returns>True if completed successfully, otherwise false</returns>
        private SNIError SendControlPacket(SNISMUXFlags flags, bool async)
        {
            byte[] headerBytes = null;

            lock (this)
            {
                GetSMUXHeaderBytes(0, (byte)flags, ref headerBytes);
            }

            SNIPacket packet = new SNIPacket(headerBytes, SNISMUXHeader.HEADER_LENGTH);

            if (async)
            {
                SNIError sniError;
                _connection.SendAsync(packet, NullCallback, false, out sniError);
                return(sniError);
            }
            else
            {
                return(_connection.Send(packet));
            }
        }
Example #4
0
        /// <summary>
        /// Send packet asynchronously
        /// </summary>
        /// <param name="packet">SNI packet</param>
        /// <param name="callback">Completion callback</param>
        /// <returns>SNI error code</returns>
        private uint InternalSendAsync(SNIPacket packet, SNIAsyncCallback callback)
        {
            Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without mux reservation in InternalSendAsync");
            lock (this)
            {
                if (_sequenceNumber >= _sendHighwater)
                {
                    return(TdsEnums.SNI_QUEUE_FULL);
                }

                SNIPacket muxedPacket = SetPacketSMUXHeader(packet);
                muxedPacket.SetCompletionCallback(callback ?? HandleSendComplete);
                return(_connection.SendAsync(muxedPacket, callback));
            }
        }