Example #1
0
        public void TestSetLength()
        {
            long length = blocks.Length;

            Assert.Throws <ArgumentOutOfRangeException> (() => blocks.SetLength(-1));

            blocks.SetLength(length + 10240);

            Assert.AreEqual(length + 10240, blocks.Length);

            blocks.SetLength(length);

            Assert.AreEqual(length, blocks.Length);
        }
Example #2
0
        private void PerformMutationOp_SetLength()
        {
            int oldLen = (int)_strmA.Length;
            int newLen = (int)(_rng.NextDouble() * 1.02 * oldLen);

            _strmA.SetLength(newLen);
            _strmB.SetLength(newLen);

            Debug.WriteLine(string.Format("SetLength = {0} (was {1})", newLen, oldLen));
        }
            /// <summary>
            /// Adds a message to the request.
            /// </summary>
            /// <param name="message">
            /// Message to add to the request
            /// (<see cref="LocalLogMessage.Release"/> is called automatically when sending completes).
            /// </param>
            /// <returns>
            /// <c>true</c> if the the request was successfully added to the request;
            /// <c>false</c> if the request is full.
            /// </returns>
            public bool AddMessage(LocalLogMessage message)
            {
                // abort, if the maximum number of messages per request is reached
                if (mMessagesPreparedToSend.Count >= mStage.mBulkRequestMaxMessageCount)
                {
                    return(false);
                }

                // store current stream position to be able to truncate the stream in case of an error
                long lastStreamPosition = mContentStream.Position;

                // serialize indexing request for the message into the stream
                SerializeIndexingRequest(message);

                if (mContentStream.Position > mStage.mBulkRequestMaxSize)
                {
                    // the maximum request size has been exceeded
                    if (lastStreamPosition < 0)
                    {
                        // the current message is so big that it does not fit into a bulk request
                        // => discard it
                        mStage.WritePipelineError(
                            $"Message is too large ({mContentStream.Position} bytes) to fit into a bulk request (max. {mStage.mBulkRequestMaxMessageCount} bytes). Discarding message...",
                            null);
                        message.Release();
                        mContentStream.SetLength(0);
                        return(true);                        // pretend to have added it to the request...
                    }

                    // truncate the stream to contain only the last messages to avoid exceeding the maximum request size
                    mContentStream.SetLength(lastStreamPosition);
                    IsFull = true;
                    return(false);
                }

                // the message was added to the request successfully
                mMessagesPreparedToSend.AddToBack(message);
                return(true);
            }
Example #4
0
        void FlushCommandQueue(MailboxAddress sender, IList <MailboxAddress> recipients, CancellationToken cancellationToken)
        {
            if (queued.Count == 0)
            {
                return;
            }

            try {
                var responses = new List <SmtpResponse> ();
                int rcpt      = 0;
                int nread;

                queue.Position = 0;
                while ((nread = queue.Read(input, 0, input.Length)) > 0)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    stream.Write(input, 0, nread);
                    logger.LogClient(input, 0, nread);
                }

                // Note: we need to read all responses from the server before we can process
                // them in case any of them have any errors so that we can RSET the state.
                for (int i = 0; i < queued.Count; i++)
                {
                    responses.Add(ReadResponse(cancellationToken));
                }

                for (int i = 0; i < queued.Count; i++)
                {
                    switch (queued [i])
                    {
                    case SmtpCommand.MailFrom:
                        ProcessMailFromResponse(responses[i], sender);
                        break;

                    case SmtpCommand.RcptTo:
                        ProcessRcptToResponse(responses[i], recipients[rcpt++]);
                        break;
                    }
                }
            } finally {
                queue.SetLength(0);
                queued.Clear();
            }
        }