Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 /// <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);
 }
Ejemplo n.º 3
0
 /// <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();
 }
Ejemplo n.º 4
0
 internal void AddMessage(FrontendMessage msg)
 {
     _messagesToSend.Add(msg);
 }