// Let's not do this forever if there is a bug hiding here somewhere...
// 65535 times should be enough for any packet load...
if (tries == std::numeric_limits<uint16_t>::max()) {
- isc_throw(BadValue, "packet split failed after trying "
+ isc_throw(Unexpected, "packet split failed after trying "
<< tries << " times.");
}
bool found = false;
}
}
-void
+OptionCollection
Pkt::cloneOptions() {
OptionCollection options;
for (auto const& option : options_) {
options.emplace(std::make_pair(option.second->getType(), option.second->clone()));
}
- options_ = options;
+ return (options);
}
void
public:
- /// @brief Clones all options so that they can be safely modified - some
- /// options reference objects directly in the server running configuration.
- void cloneOptions();
+ /// @brief Clones all options so that they can be safely modified.
+ ///
+ /// @return A container with option clones.
+ OptionCollection cloneOptions();
/// @brief Returns the first option of specified type.
///
///
/// @param pkt Pointer to the packet.
ScopedPktOptionsCopy(PktType& pkt) : pkt_(pkt), options_(pkt.options_) {
- pkt.cloneOptions();
+ pkt_.options_ = pkt_.cloneOptions();
}
/// @brief Destructor.
isc_throw(InvalidOperation, "Can't build Pkt4 packet. HWAddr not set.");
}
+ // This object is necessary to restore the packet options after performing
+ // splitOptions4 when function scope ends. It creates a container of option
+ // clones which are split and packed.
ScopedPkt4OptionsCopy scoped_options(*this);
// Clear the output buffer to make sure that consecutive calls to pack()
ASSERT_EQ(option, pkt->getOption(DHO_BOOT_FILE_NAME));
std::string expected = pkt->toText();
pkt->pack();
- auto buf = pkt->getBuffer();
+ OutputBuffer buf = pkt->getBuffer();
{
ScopedPkt4OptionsCopy oc(*pkt);
ASSERT_NE(pkt->options_, options);
ASSERT_EQ(option, pkt->getOption(D6O_BOOTFILE_URL));
std::string expected = pkt->toText();
pkt->pack();
- auto buf = pkt->getBuffer();
+ OutputBuffer buf = pkt->getBuffer();
{
ScopedPkt6OptionsCopy oc(*pkt);
ASSERT_NE(pkt->options_, options);