// Used to simulate a packet-based transport. class FakePacketTransport : public PacketTransportInternal {
public: explicit FakePacketTransport(const std::string& transport_name)
: transport_name_(transport_name) {}
~FakePacketTransport() override { if (dest_ && dest_->dest_ == this) {
dest_->dest_ = nullptr;
}
}
// SetWritable, SetReceiving and SetDestination are the main methods that can // be used for testing, to simulate connectivity or lack thereof. void SetWritable(bool writable) { set_writable(writable); } void SetReceiving(bool receiving) { set_receiving(receiving); }
// Simulates the two transports connecting to each other. // If `asymmetric` is true this method only affects this FakePacketTransport. // If false, it affects `dest` as well. void SetDestination(FakePacketTransport* dest, bool asymmetric) { if (dest) {
dest_ = dest;
set_writable(true); if (!asymmetric) {
dest->SetDestination(this, true);
}
} else { // Simulates loss of connectivity, by asymmetrically forgetting dest_.
dest_ = nullptr;
set_writable(false);
}
}
SentPacketInfo sent_packet(options.packet_id, TimeMillis()); // Because handlers of NotifySentPacket may be sending packets, // dispatch this call to a new task.
TaskQueueBase::Current()->PostTask(
SafeTask(safety_.flag(),
[this, sent_packet] { NotifySentPacket(this, sent_packet); })); return static_cast<int>(len);
}
int SetOption(Socket::Option opt, int value) override {
options_[opt] = value; return0;
}
bool GetOption(Socket::Option opt, int* value) override { auto it = options_.find(opt); if (it == options_.end()) { returnfalse;
}
*value = it->second; return true;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.