/// <summary> /// Send control packet /// </summary> /// <param name="flags">SMUX header flags</param> private void SendControlPacket(SNISMUXFlags flags) { long scopeID = SqlClientEventSource.Log.TrySNIScopeEnterEvent("SNIMarsHandle.SendControlPacket | SNI | INFO | SCOPE | Entering Scope {0}"); try { SNIPacket packet = RentPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.INFO, "MARS Session Id {0}, Packet rented {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); #endif lock (this) { SetupSMUXHeader(0, flags); _currentHeader.Write(packet.GetHeaderBuffer(SNISMUXHeader.HEADER_LENGTH)); packet.SetHeaderActive(); } _connection.Send(packet); ReturnPacket(packet); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.INFO, "MARS Session Id {0}, Packet returned {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); ; #endif } finally { SqlClientEventSource.Log.TrySNIScopeLeaveEvent(scopeID); } }
private void SetupSMUXHeader(int length, SNISMUXFlags flags) { Debug.Assert(Monitor.IsEntered(this), "must take lock on self before updating mux header"); _currentHeader.SMID = 83; _currentHeader.flags = (byte)flags; _currentHeader.sessionId = _sessionId; _currentHeader.length = (uint)SNISMUXHeader.HEADER_LENGTH + (uint)length; _currentHeader.sequenceNumber = ((flags == SNISMUXFlags.SMUX_FIN) || (flags == SNISMUXFlags.SMUX_ACK)) ? _sequenceNumber - 1 : _sequenceNumber++; _currentHeader.highwater = _receiveHighwater; _receiveHighwaterLastAck = _currentHeader.highwater; }
private void GetSMUXHeaderBytes(int length, SNISMUXFlags flags, Span <byte> bytes) { _currentHeader.SMID = 83; _currentHeader.flags = (byte)flags; _currentHeader.sessionId = _sessionId; _currentHeader.length = (uint)SNISMUXHeader.HEADER_LENGTH + (uint)length; _currentHeader.sequenceNumber = ((flags == SNISMUXFlags.SMUX_FIN) || (flags == SNISMUXFlags.SMUX_ACK)) ? _sequenceNumber - 1 : _sequenceNumber++; _currentHeader.highwater = _receiveHighwater; _receiveHighwaterLastAck = _currentHeader.highwater; _currentHeader.Write(bytes); }
/// <summary> /// Send control packet /// </summary> /// <param name="flags">SMUX header flags</param> private void SendControlPacket(SNISMUXFlags flags) { SNIPacket packet = new SNIPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0); lock (this) { SetupSMUXHeader(0, flags); _currentHeader.Write(packet.GetHeaderBuffer(SNISMUXHeader.HEADER_LENGTH)); packet.SetHeaderActive(); } _connection.Send(packet); }
/// <summary> /// Send control packet /// </summary> /// <param name="flags">SMUX header flags</param> private void SendControlPacket(SNISMUXFlags flags) { byte[] headerBytes = null; lock (this) { GetSMUXHeaderBytes(0, (byte)flags, ref headerBytes); } SNIPacket packet = new SNIPacket(); packet.SetData(headerBytes, SNISMUXHeader.HEADER_LENGTH); _connection.Send(packet); }
/// <summary> /// Send control packet /// </summary> /// <param name="flags">SMUX header flags</param> private void SendControlPacket(SNISMUXFlags flags) { Span <byte> headerBytes = stackalloc byte[SNISMUXHeader.HEADER_LENGTH]; lock (this) { GetSMUXHeaderBytes(0, flags, headerBytes); } SNIPacket packet = new SNIPacket(SNISMUXHeader.HEADER_LENGTH); packet.AppendData(headerBytes); _connection.Send(packet); }
private SNISMUXHeader SetupSMUXHeader(int length, SNISMUXFlags flags) { Debug.Assert(Monitor.IsEntered(this), "must take lock on self before updating smux header"); SNISMUXHeader header = new SNISMUXHeader(); header.Set( smid: 83, flags: (byte)flags, sessionID: _sessionId, length: (uint)SNISMUXHeader.HEADER_LENGTH + (uint)length, sequenceNumber: ((flags == SNISMUXFlags.SMUX_FIN) || (flags == SNISMUXFlags.SMUX_ACK)) ? _sequenceNumber - 1 : _sequenceNumber++, highwater: _receiveHighwater ); _receiveHighwaterLastAck = header.Highwater; return(header); }
/// <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); } }
/// <summary> /// Send control packet /// </summary> /// <param name="flags">SMUX header flags</param> private void SendControlPacket(SNISMUXFlags flags) { long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsHandle.SendControlPacket |SNI|INFO|SCOPE>"); try { SNIPacket packet = new SNIPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0); lock (this) { SetupSMUXHeader(0, flags); _currentHeader.Write(packet.GetHeaderBuffer(SNISMUXHeader.HEADER_LENGTH)); packet.SetHeaderActive(); } _connection.Send(packet); } finally { SqlClientEventSource.Log.SNIScopeLeaveEvent(scopeID); } }
/// <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)); } }
/// <summary> /// Send control packet /// </summary> /// <param name="flags">SMUX header flags</param> private void SendControlPacket(SNISMUXFlags flags) { using (TrySNIEventScope.Create("SNIMarsHandle.SendControlPacket | SNI | INFO | SCOPE | Entering Scope {0}")) { SNIPacket packet = RentPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Packet rented {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); #endif lock (this) { SNISMUXHeader header = SetupSMUXHeader(0, flags); header.Write(packet.GetHeaderBuffer(SNISMUXHeader.HEADER_LENGTH)); packet.SetHeaderActive(); } _connection.Send(packet); ReturnPacket(packet); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Packet returned {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); ; #endif } }
/// <summary> /// Send control packet /// </summary> /// <param name="flags">SMUX header flags</param> private void SendControlPacket(SNISMUXFlags flags) { byte[] headerBytes = null; lock (this) { GetSMUXHeaderBytes(0, (byte)flags, ref headerBytes); } SNIPacket packet = new SNIPacket(null); packet.SetData(headerBytes, SNISMUXHeader.HEADER_LENGTH); _connection.Send(packet); }