void SendMessage(FrontendMessage msg) { try { _log.DebugFormat("Sending: {0}", msg); var asSimple = msg as SimpleFrontendMessage; if (asSimple != null) { if (asSimple.Length > Buffer.WriteSpaceLeft) { Buffer.Flush(); } Contract.Assume(Buffer.WriteSpaceLeft >= asSimple.Length); asSimple.Write(Buffer); return; } var asComplex = msg as ChunkingFrontendMessage; if (asComplex != null) { var directBuf = new DirectBuffer(); while (!asComplex.Write(Buffer, ref directBuf)) { Buffer.Flush(); // The following is an optimization hack for writing large byte arrays without passing // through our buffer if (directBuf.Buffer != null) { Buffer.Underlying.Write(directBuf.Buffer, 0, directBuf.Size == 0 ? directBuf.Buffer.Length : directBuf.Size); directBuf.Buffer = null; directBuf.Size = 0; } } return; } throw PGUtil.ThrowIfReached(); } catch { State = ConnectorState.Broken; throw; } }
/// <summary> /// Prepends a message to be sent at the beginning of the next message chain. /// </summary> internal void PrependMessage(FrontendMessage msg) { _prependedMessages++; _messagesToSend.Add(msg); }
/// <summary> /// Sends a single frontend message, used for simple messages such as rollback, etc. /// Note that additional prepend messages may be previously enqueued, and will be sent along /// with this message. /// </summary> /// <param name="msg"></param> void SendSingleMessage(FrontendMessage msg) { AddMessage(msg); SendAllMessages(); }
internal void AddMessage(FrontendMessage msg) { _messagesToSend.Add(msg); }