本文整理汇总了C#中Response.AddOption方法的典型用法代码示例。如果您正苦于以下问题:C# Response.AddOption方法的具体用法?C# Response.AddOption怎么用?C# Response.AddOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response.AddOption方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNextResponseBlock
private Response GetNextResponseBlock(Response response, BlockwiseStatus status)
{
Int32 szx = status.CurrentSZX;
Int32 num = status.CurrentNUM;
Response block = new Response(response.StatusCode);
// block.setType(response.getType()); // NO! First block has type from origin response, all other depend on current request
block.Destination = response.Destination;
block.Token = response.Token;
block.SetOptions(response.GetOptions());
block.TimedOut += (o, e) => response.IsTimedOut = true;
Int32 payloadSize = response.PayloadSize;
Int32 currentSize = 1 << (4 + szx);
Int32 from = num * currentSize;
if (payloadSize > 0 && payloadSize > from)
{
Int32 to = Math.Min((num + 1) * currentSize, response.PayloadSize);
Int32 length = to - from;
Byte[] blockPayload = new Byte[length];
Array.Copy(response.Payload, from, blockPayload, 0, length);
block.Payload = blockPayload;
Boolean m = to < response.PayloadSize;
block.AddOption(new BlockOption(OptionType.Block2, num, szx, m));
block.Last = !m;
status.Complete = !m;
}
else
{
block.AddOption(new BlockOption(OptionType.Block2, num, szx, false));
block.Last = true;
status.Complete = true;
}
return block;
}
示例2: ReceiveResponse
//.........这里部分代码省略.........
}
BlockOption block2 = response.Block2;
if (block2 != null)
{
BlockwiseStatus status = FindResponseBlockStatus(exchange, response);
if (block2.NUM == status.CurrentNUM)
{
// We got the block we expected :-)
status.AddBlock(response.Payload);
Int32? obs = response.Observe;
if (obs.HasValue)
status.Observe = obs.Value;
// notify blocking progress
exchange.Request.FireResponding(response);
if (status.IsRandomAccess)
{
// The client has requested this specifc block and we deliver it
exchange.Response = response;
base.ReceiveResponse(nextLayer, exchange, response);
}
else if (block2.M)
{
if (log.IsDebugEnabled)
log.Debug("Request the next response block");
// TODO: If this is a notification, do we have to use
// another token now?
Request request = exchange.Request;
Int32 num = block2.NUM + 1;
Int32 szx = block2.SZX;
Boolean m = false;
Request block = new Request(request.Method);
block.Token = response.Token;
block.SetOptions(request.GetOptions());
block.Destination = request.Destination;
block.Type = request.Type; // NON could make sense over SMS or similar transports
block.SetOption(new BlockOption(OptionType.Block2, num, szx, m));
status.CurrentNUM = num;
// to make it easier for Observe, we do not re-use the Token
//if (!response.HasOption(OptionType.Observe))
//{
// block.Token = request.Token;
//}
// make sure not to use Observe for block retrieval
block.RemoveOptions(OptionType.Observe);
exchange.CurrentRequest = block;
base.SendRequest(nextLayer, exchange, block);
}
else
{
if (log.IsDebugEnabled)
log.Debug("We have received all " + status.BlockCount + " blocks of the response. Assemble and deliver.");
Response assembled = new Response(response.StatusCode);
AssembleMessage(status, assembled, response);
assembled.Type = response.Type;
// set overall transfer RTT
assembled.RTT = (DateTime.Now - exchange.Timestamp).TotalMilliseconds;
// Check if this response is a notification
Int32 observe = status.Observe;
if (observe != BlockwiseStatus.NoObserve)
{
assembled.AddOption(Option.Create(OptionType.Observe, observe));
// This is necessary for notifications that are sent blockwise:
// Reset block number AND container with all blocks
exchange.ResponseBlockStatus = null;
}
if (log.IsDebugEnabled)
log.Debug("Assembled response: " + assembled);
exchange.Response = assembled;
base.ReceiveResponse(nextLayer, exchange, assembled);
}
}
else
{
// ERROR, wrong block number (server error)
// TODO: This scenario is not specified in the draft.
// Currently, we reject it and cancel the request.
if (log.IsWarnEnabled)
log.Warn("Wrong block number. Expected " + status.CurrentNUM + " but received " + block2.NUM + ". Reject response; exchange has failed.");
if (response.Type == MessageType.CON)
{
EmptyMessage rst = EmptyMessage.NewRST(response);
base.SendEmptyMessage(nextLayer, exchange, rst);
}
exchange.Request.IsCancelled = true;
}
}
}