public void StartPacket(TdsPacketType type) { if (type != TdsPacketType.Cancel && inBufferIndex != inBufferLength) { inBufferIndex = inBufferLength; } packetType = type; nextOutBufferIndex = headerLength; }
public void SendPacket() { // Reset connection flag is only valid for SQLBatch/RPC/DTC messages if (packetType != TdsPacketType.Query && packetType != TdsPacketType.RPC) { connReset = false; } SendPhysicalPacket(true); nextOutBufferIndex = 0; packetType = TdsPacketType.None; // Reset connection-reset flag to false - as any exception would anyway close // the whole connection connReset = false; packetsSent = 1; }
public void OnReadPacketCallback(IAsyncResult socketAsyncResult) { TdsAsyncResult ar = (TdsAsyncResult)socketAsyncResult.AsyncState; int nread = stream.EndRead(socketAsyncResult); int n; while (nread < 8) { n = Read(tmpBuf, nread, 8 - nread); if (n <= 0) { socket = null; stream.Close(); throw new IOException(n == 0 ? "Connection lost" : "Connection error"); } nread += n; } TdsPacketType packetType = (TdsPacketType)tmpBuf[0]; if (packetType != TdsPacketType.Logon && packetType != TdsPacketType.Query && packetType != TdsPacketType.Reply) { throw new Exception(String.Format("Unknown packet type {0}", tmpBuf[0])); } // figure out how many bytes are remaining in this packet. int len = Ntohs(tmpBuf, 2) - 8; if (len >= inBuffer.Length) { inBuffer = new byte[len]; } if (len < 0) { throw new Exception(String.Format("Confused by a length of {0}", len)); } GetPhysicalPacketData(len); int value = len + 8; ar.ReturnValue = ((object)value); // packet size ar.MarkComplete(); }
private int GetPhysicalPacketHeader() { int nread = 0; int n; // read the header while (nread < 8) { n = Read(tmpBuf, nread, 8 - nread); if (n <= 0) { socket = null; stream.Close(); throw new IOException(n == 0 ? "Connection lost" : "Connection error"); } nread += n; } TdsPacketType packetType = (TdsPacketType)tmpBuf[0]; if (packetType != TdsPacketType.Logon && packetType != TdsPacketType.Query && packetType != TdsPacketType.Reply) { throw new Exception(String.Format("Unknown packet type {0}", tmpBuf[0])); } // figure out how many bytes are remaining in this packet. int len = Ntohs(tmpBuf, 2) - 8; if (len >= inBuffer.Length) { inBuffer = new byte[len]; } if (len < 0) { throw new Exception(String.Format("Confused by a length of {0}", len)); } return(len); }
public void StartPacket (TdsPacketType type) { if (type != TdsPacketType.Cancel && inBufferIndex != inBufferLength) inBufferIndex = inBufferLength; packetType = type; nextOutBufferIndex = headerLength; }
public void SendPacket () { // Reset connection flag is only valid for SQLBatch/RPC/DTC messages if (packetType != TdsPacketType.Query && packetType != TdsPacketType.RPC) connReset = false; SendPhysicalPacket (true); nextOutBufferIndex = 0; packetType = TdsPacketType.None; // Reset connection-reset flag to false - as any exception would anyway close // the whole connection connReset = false; packetsSent = 1; }
public void SendPacket () { SendPhysicalPacket (true); nextOutBufferIndex = 0; packetType = TdsPacketType.None; }