Esempio n. 1
0
File: Message.cs Progetto: xrl/scamp
 /// <summary>
 /// Explicitly marks a message body as unwanted.
 /// </summary>
 public void Discard()
 {
     if (Consumed)
     {
         throw new InvalidOperationException("consumption already started");
     }
     onFull     = Discarder;
     maxBuffer  = 0;
     dataBuffer = new byte[0];
 }
Esempio n. 2
0
File: Message.cs Progetto: xrl/scamp
        /// <summary>
        /// Sets up a message for all-at-once consumption.
        /// </summary>
        /// <remarks>
        /// This function will cause the message object to buffer any data streamed to it until the message is done.
        /// To avoid threats of denial of service caused by buggy or maliciously large payloads, the payload size
        /// may be limited using the <paramref name="maxBuffer"/> argument.  If the limit is exceeded, the message
        /// will be truncated with an error.  Note that the limit is not used if the production mode is all-at-once.
        /// </remarks>
        /// <param name="maxBuffer">Maximum number of bytes to buffer</param>
        /// <param name="full">Callback to call after message is ready</param>
        public void Consume(int maxBuffer, FullDelegate full)
        {
            if (Consumed)
            {
                throw new InvalidOperationException("consumption already started");
            }
            if (maxBuffer < 0)
            {
                throw new ArgumentOutOfRangeException("maxBuffer");
            }
            if (full == null)
            {
                throw new ArgumentNullException("full");
            }

            onFull          = full;
            this.maxBuffer  = maxBuffer;
            this.dataBuffer = new byte[128];
        }