Example #1
0
        /// <summary>
        /// Notice:
        /// This method is used by SendResponse and ReceiveResponse.
        /// Be careful, making changes to the status in here.
        /// </summary>
        private BlockwiseStatus FindResponseBlockStatus(Exchange exchange, Response response)
        {
            BlockwiseStatus status = exchange.ResponseBlockStatus;

            if (status == null)
            {
                int blockSize = _defaultBlockSize;
                if (response.Session != null && response.Session.IsReliable)
                {
                    blockSize = response.Session.MaxSendSize - 100;
                }
                status = new BlockwiseStatus(response.ContentType)
                {
                    CurrentSZX = BlockOption.EncodeSZX(blockSize)
                };
                exchange.ResponseBlockStatus = status;

                log.Debug(m => m("There is no blockwise status yet. Create and set new Block2 status: {0}", status));
            }
            else
            {
                log.Debug(m => m("Current Block2 status: {0}", status));
            }

            // sets a timeout to complete exchange
            PrepareBlockCleanup(exchange);

            return(status);
        }
Example #2
0
        /// <summary>
        /// Initializes a transfer layer.
        /// </summary>
        /// <param name="defaultBlockSize">The default block size used for block-wise transfers or -1 to disable outgoing block-wise transfers</param>
        public TransferLayer(Int32 defaultBlockSize)
        {
            if (defaultBlockSize == 0)
            {
                defaultBlockSize = CoapConstants.DefaultBlockSize;
            }

            if (defaultBlockSize > 0)
            {
                _defaultSZX = BlockOption.EncodeSZX(defaultBlockSize);
                if (!BlockOption.ValidSZX(_defaultSZX))
                {
                    _defaultSZX = defaultBlockSize > 1024 ? 6 : BlockOption.EncodeSZX(defaultBlockSize & 0x07f0);
                    if (log.IsWarnEnabled)
                    {
                        log.Warn(String.Format("TransferLayer - Unsupported block size {0}, using {1} instead", defaultBlockSize, BlockOption.DecodeSZX(_defaultSZX)));
                    }
                }
            }
            else
            {
                // disable outgoing blockwise transfers
                _defaultSZX = -1;
            }
        }
Example #3
0
        /// <summary>
        /// Notice:
        /// This method is used by SendRequest and ReceiveRequest.
        /// Be careful, making changes to the status in here.
        /// </summary>
        private BlockwiseStatus FindRequestBlockStatus(Exchange exchange, Request request)
        {
            BlockwiseStatus status = exchange.RequestBlockStatus;

            if (status == null)
            {
                status                      = new BlockwiseStatus(request.ContentType);
                status.CurrentSZX           = BlockOption.EncodeSZX(_defaultBlockSize);
                exchange.RequestBlockStatus = status;
                if (log.IsDebugEnabled)
                {
                    log.Debug("There is no assembler status yet. Create and set new Block1 status: " + status);
                }
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Current Block1 status: " + status);
                }
            }
            // sets a timeout to complete exchange
            PrepareBlockCleanup(exchange);
            return(status);
        }
Example #4
0
        private BlockwiseStatus FindResponseBlockStatus(Exchange exchange, Response response)
        {
            // NOTICE: This method is used by sendResponse and receiveResponse. Be
            // careful, making changes to the status in here.
            BlockwiseStatus status = exchange.ResponseBlockStatus;

            if (status == null)
            {
                status                       = new BlockwiseStatus(response.ContentType);
                status.CurrentSZX            = BlockOption.EncodeSZX(_defaultBlockSize);
                exchange.ResponseBlockStatus = status;
                if (log.IsDebugEnabled)
                {
                    log.Debug("There is no blockwise status yet. Create and set new block2 status: " + status);
                }
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Current blockwise status: " + status);
                }
            }
            return(status);
        }