Run clang format on pseudotcp/test

Bug: webrtc:5273
Change-Id: Ib2e5b749951c805417fd50022172c604a4fe241b
Reviewed-on: https://webrtc-review.googlesource.com/27122
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21128}
This commit is contained in:
Steve Anton 2017-11-29 10:19:58 -08:00 committed by Commit Bot
parent 02384b8e3f
commit cc65bd018d
2 changed files with 105 additions and 120 deletions

View File

@ -125,8 +125,10 @@ const uint8_t TCP_OPT_NOOP = 1; // No-op.
const uint8_t TCP_OPT_MSS = 2; // Maximum segment size.
const uint8_t TCP_OPT_WND_SCALE = 3; // Window scale factor.
const long DEFAULT_TIMEOUT = 4000; // If there are no pending clocks, wake up every 4 seconds
const long CLOSED_TIMEOUT = 60 * 1000; // If the connection is closed, once per minute
const long DEFAULT_TIMEOUT =
4000; // If there are no pending clocks, wake up every 4 seconds
const long CLOSED_TIMEOUT =
60 * 1000; // If the connection is closed, once per minute
#if PSEUDO_KEEPALIVE
// !?! Rethink these times
@ -256,8 +258,7 @@ PseudoTcp::PseudoTcp(IPseudoTcpNotify* notify, uint32_t conv)
m_support_wnd_scale = true;
}
PseudoTcp::~PseudoTcp() {
}
PseudoTcp::~PseudoTcp() {}
int PseudoTcp::Connect() {
if (m_state != TCP_LISTEN) {
@ -533,8 +534,8 @@ IPseudoTcpNotify::WriteResult PseudoTcp::packet(uint32_t seq,
if (len) {
size_t bytes_read = 0;
rtc::StreamResult result = m_sbuf.ReadOffset(
buffer.get() + HEADER_SIZE, len, offset, &bytes_read);
rtc::StreamResult result =
m_sbuf.ReadOffset(buffer.get() + HEADER_SIZE, len, offset, &bytes_read);
RTC_DCHECK(result == rtc::SR_SUCCESS);
RTC_DCHECK(static_cast<uint32_t>(bytes_read) == len);
}
@ -551,9 +552,10 @@ IPseudoTcpNotify::WriteResult PseudoTcp::packet(uint32_t seq,
IPseudoTcpNotify::WriteResult wres = m_notify->TcpWritePacket(
this, reinterpret_cast<char*>(buffer.get()), len + HEADER_SIZE);
// Note: When len is 0, this is an ACK packet. We don't read the return value for those,
// and thus we won't retry. So go ahead and treat the packet as a success (basically simulate
// as if it were dropped), which will prevent our timers from being messed up.
// Note: When len is 0, this is an ACK packet. We don't read the return value
// for those, and thus we won't retry. So go ahead and treat the packet as a
// success (basically simulate as if it were dropped), which will prevent our
// timers from being messed up.
if ((wres != IPseudoTcpNotify::WR_SUCCESS) && (0 != len))
return wres;
@ -603,9 +605,9 @@ bool PseudoTcp::clock_check(uint32_t now, long& nTimeout) {
size_t snd_buffered = 0;
m_sbuf.GetBuffered(&snd_buffered);
if ((m_shutdown == SD_GRACEFUL)
&& ((m_state != TCP_ESTABLISHED)
|| ((snd_buffered == 0) && (m_t_ack == 0)))) {
if ((m_shutdown == SD_GRACEFUL) &&
((m_state != TCP_ESTABLISHED) ||
((snd_buffered == 0) && (m_t_ack == 0)))) {
return false;
}
@ -641,7 +643,8 @@ bool PseudoTcp::clock_check(uint32_t now, long& nTimeout) {
}
bool PseudoTcp::process(Segment& seg) {
// If this is the wrong conversation, send a reset!?! (with the correct conversation?)
// If this is the wrong conversation, send a reset!?! (with the correct
// conversation?)
if (seg.conv != m_conv) {
// if ((seg.flags & FLAG_RST) == 0) {
// packet(tcb, seg.ack, 0, FLAG_RST, 0, 0);
@ -782,7 +785,8 @@ bool PseudoTcp::process(Segment& seg) {
}
}
} else if (seg.ack == m_snd_una) {
// !?! Note, tcp says don't do this... but otherwise how does a closed window become open?
// !?! Note, tcp says don't do this... but otherwise how does a closed
// window become open?
m_snd_wnd = static_cast<uint32_t>(seg.wnd) << m_swnd_scale;
// Check duplicate acks
@ -843,7 +847,8 @@ bool PseudoTcp::process(Segment& seg) {
// 1) Segment is too old (they missed an ACK) (immediately)
// 2) Segment is too new (we missed a segment) (immediately)
// 3) Segment has data (so we need to ACK!) (delayed)
// ... so the only time we don't need to ACK, is an empty segment that points to rcv_nxt!
// ... so the only time we don't need to ACK, is an empty segment that points
// to rcv_nxt!
SendFlags sflags = sfNone;
if (seg.seq != m_rcv_nxt) {
@ -975,10 +980,8 @@ bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {
while (true) {
uint32_t seq = seg->seq;
uint8_t flags = (seg->bCtrl ? FLAG_CTL : 0);
IPseudoTcpNotify::WriteResult wres = packet(seq,
flags,
seg->seq - m_snd_una,
nTransmit);
IPseudoTcpNotify::WriteResult wres =
packet(seq, flags, seg->seq - m_snd_una, nTransmit);
if (wres == IPseudoTcpNotify::WR_SUCCESS)
break;
@ -995,7 +998,8 @@ bool PseudoTcp::transmit(const SList::iterator& seg, uint32_t now) {
RTC_LOG_F(LS_VERBOSE) << "MTU too small";
return false;
}
// !?! We need to break up all outstanding and pending packets and then retransmit!?!
// !?! We need to break up all outstanding and pending packets and then
// retransmit!?!
m_mss = PACKET_MAXIMUMS[++m_msslevel] - PACKET_OVERHEAD;
m_cwnd = 2 * m_mss; // I added this... haven't researched actual formula
@ -1137,8 +1141,7 @@ void PseudoTcp::closedown(uint32_t err) {
// notify(evClose, err);
}
void
PseudoTcp::adjustMTU() {
void PseudoTcp::adjustMTU() {
// Determine our current mss level, so that we can adjust appropriately later
for (m_msslevel = 0; PACKET_MAXIMUMS[m_msslevel + 1] > 0; ++m_msslevel) {
if (static_cast<uint16_t>(PACKET_MAXIMUMS[m_msslevel]) <= m_mtu_advise) {
@ -1155,20 +1158,17 @@ PseudoTcp::adjustMTU() {
m_cwnd = std::max(m_cwnd, m_mss);
}
bool
PseudoTcp::isReceiveBufferFull() const {
bool PseudoTcp::isReceiveBufferFull() const {
size_t available_space = 0;
m_rbuf.GetWriteRemaining(&available_space);
return !available_space;
}
void
PseudoTcp::disableWindowScale() {
void PseudoTcp::disableWindowScale() {
m_support_wnd_scale = false;
}
void
PseudoTcp::queueConnectMessage() {
void PseudoTcp::queueConnectMessage() {
rtc::ByteBufferWriter buf(rtc::ByteBuffer::ORDER_NETWORK);
buf.WriteUInt8(CTL_CONNECT);

View File

@ -30,13 +30,9 @@ class PseudoTcpForTest : public cricket::PseudoTcp {
PseudoTcpForTest(cricket::IPseudoTcpNotify* notify, uint32_t conv)
: PseudoTcp(notify, conv) {}
bool isReceiveBufferFull() const {
return PseudoTcp::isReceiveBufferFull();
}
bool isReceiveBufferFull() const { return PseudoTcp::isReceiveBufferFull(); }
void disableWindowScale() {
PseudoTcp::disableWindowScale();
}
void disableWindowScale() { PseudoTcp::disableWindowScale(); }
};
class PseudoTcpTestBase : public testing::Test,
@ -67,12 +63,8 @@ class PseudoTcpTestBase : public testing::Test,
remote_.NotifyMTU(mtu);
remote_mtu_ = mtu;
}
void SetDelay(int delay) {
delay_ = delay;
}
void SetLoss(int percent) {
loss_ = percent;
}
void SetDelay(int delay) { delay_ = delay; }
void SetLoss(int percent) { loss_ = percent; }
void SetOptNagling(bool enable_nagles) {
local_.SetOption(PseudoTcp::OPT_NODELAY, !enable_nagles);
remote_.SetOption(PseudoTcp::OPT_NODELAY, !enable_nagles);
@ -91,12 +83,8 @@ class PseudoTcpTestBase : public testing::Test,
void SetLocalOptRcvBuf(int size) {
local_.SetOption(PseudoTcp::OPT_RCVBUF, size);
}
void DisableRemoteWindowScale() {
remote_.disableWindowScale();
}
void DisableLocalWindowScale() {
local_.disableWindowScale();
}
void DisableRemoteWindowScale() { remote_.disableWindowScale(); }
void DisableLocalWindowScale() { local_.disableWindowScale(); }
protected:
int Connect() {
@ -111,8 +99,14 @@ class PseudoTcpTestBase : public testing::Test,
UpdateLocalClock();
}
enum { MSG_LPACKET, MSG_RPACKET, MSG_LCLOCK, MSG_RCLOCK, MSG_IOCOMPLETE,
MSG_WRITE};
enum {
MSG_LPACKET,
MSG_RPACKET,
MSG_LCLOCK,
MSG_RCLOCK,
MSG_IOCOMPLETE,
MSG_WRITE
};
virtual void OnTcpOpen(PseudoTcp* tcp) {
// Consider ourselves connected when the local side gets OnTcpOpen.
// OnTcpWriteable isn't fired at open, so we trigger it now.
@ -137,7 +131,8 @@ class PseudoTcpTestBase : public testing::Test,
}
}
virtual WriteResult TcpWritePacket(PseudoTcp* tcp,
const char* buffer, size_t len) {
const char* buffer,
size_t len) {
// Randomly drop the desired percentage of packets.
// Also drop packets that are larger than the configured MTU.
if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) {
@ -167,15 +162,13 @@ class PseudoTcpTestBase : public testing::Test,
virtual void OnMessage(rtc::Message* message) {
switch (message->message_id) {
case MSG_LPACKET: {
const std::string& s(
rtc::UseMessageData<std::string>(message->pdata));
const std::string& s(rtc::UseMessageData<std::string>(message->pdata));
local_.NotifyPacket(s.c_str(), s.size());
UpdateLocalClock();
break;
}
case MSG_RPACKET: {
const std::string& s(
rtc::UseMessageData<std::string>(message->pdata));
const std::string& s(rtc::UseMessageData<std::string>(message->pdata));
remote_.NotifyPacket(s.c_str(), s.size());
UpdateRemoteClock();
break;
@ -235,8 +228,8 @@ class PseudoTcpTest : public PseudoTcpTestBase {
// EXPECT_EQ(0, local_.GetError());
// EXPECT_EQ(0, remote_.GetError());
EXPECT_EQ(static_cast<size_t>(size), received);
EXPECT_EQ(0, memcmp(send_stream_.GetBuffer(),
recv_stream_.GetBuffer(), size));
EXPECT_EQ(0,
memcmp(send_stream_.GetBuffer(), recv_stream_.GetBuffer(), size));
RTC_LOG(LS_INFO) << "Transferred " << received << " bytes in " << elapsed
<< " ms (" << size * 8 / elapsed << " Kbps)";
}
@ -314,18 +307,14 @@ class PseudoTcpTest : public PseudoTcpTestBase {
rtc::MemoryStream recv_stream_;
};
class PseudoTcpTestPingPong : public PseudoTcpTestBase {
public:
PseudoTcpTestPingPong()
: iterations_remaining_(0),
sender_(NULL),
receiver_(NULL),
bytes_per_send_(0) {
}
void SetBytesPerSend(int bytes) {
bytes_per_send_ = bytes;
}
bytes_per_send_(0) {}
void SetBytesPerSend(int bytes) { bytes_per_send_ = bytes; }
void TestPingPong(int size, int iterations) {
uint32_t start, elapsed;
iterations_remaining_ = iterations;
@ -411,8 +400,7 @@ class PseudoTcpTestPingPong : public PseudoTcpTestBase {
do {
send_stream_.GetPosition(&position);
tosend = bytes_per_send_ ? bytes_per_send_ : sizeof(block);
if (send_stream_.Read(block, tosend, &tosend, NULL) !=
rtc::SR_EOS) {
if (send_stream_.Read(block, tosend, &tosend, NULL) != rtc::SR_EOS) {
sent = sender_->Send(block, tosend);
UpdateLocalClock();
if (sent != -1) {
@ -500,11 +488,9 @@ class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase {
private:
// IPseudoTcpNotify interface
virtual void OnTcpReadable(PseudoTcp* tcp) {
}
virtual void OnTcpReadable(PseudoTcp* tcp) {}
virtual void OnTcpWriteable(PseudoTcp* tcp) {
}
virtual void OnTcpWriteable(PseudoTcp* tcp) {}
void ReadUntilIOPending() {
char block[kBlockSize];
@ -555,8 +541,7 @@ class PseudoTcpTestReceiveWindow : public PseudoTcpTestBase {
} while (sent > 0);
// At this point, we've filled up the available space in the send queue.
int message_queue_size =
static_cast<int>(rtc::Thread::Current()->size());
int message_queue_size = static_cast<int>(rtc::Thread::Current()->size());
// The message queue will always have at least 2 messages, an RCLOCK and
// an LCLOCK, since they are added back on the delay queue at the same time
// they are pulled off and therefore are never really removed.