proxygen
proxygen::ByteEventTracker Class Reference

#include <ByteEventTracker.h>

Inheritance diagram for proxygen::ByteEventTracker:
proxygen::MockByteEventTracker

Classes

class  Callback
 

Public Member Functions

virtual ~ByteEventTracker ()
 
 ByteEventTracker (Callback *callback)
 
virtual void absorb (ByteEventTracker &&other)
 
void setCallback (Callback *callback)
 
virtual size_t drainByteEvents ()
 
virtual bool processByteEvents (std::shared_ptr< ByteEventTracker > self, uint64_t bytesWritten)
 
void addPingByteEvent (size_t pingSize, TimePoint timestamp, uint64_t bytesScheduled)
 
void addFirstBodyByteEvent (uint64_t offset, HTTPTransaction *txn)
 
virtual void addFirstHeaderByteEvent (uint64_t offset, HTTPTransaction *txn)
 
virtual void addLastByteEvent (HTTPTransaction *txn, uint64_t byteNo) noexcept
 
virtual void addTrackedByteEvent (HTTPTransaction *txn, uint64_t byteNo) noexcept
 
virtual void addAckByteEvent (uint64_t, HTTPTransaction *)
 
virtual uint64_t preSend (bool *, bool *, uint64_t)
 
virtual void setTTLBAStats (TTLBAStats *)
 

Protected Member Functions

virtual void eomEventProcessed ()
 

Protected Attributes

folly::IntrusiveList< ByteEvent,&ByteEvent::listHookbyteEvents_
 
Callbackcallback_
 

Detailed Description

ByteEventTracker can be used to fire application callbacks when a given byte of a transport stream has been processed. The primary usage is to fire the callbacks when the byte is accepted by the transport, not when the byte has been written on the wire, or acknowledged.

Subclasses may implement handling of acknowledgement timing.

Definition at line 29 of file ByteEventTracker.h.

Constructor & Destructor Documentation

proxygen::ByteEventTracker::~ByteEventTracker ( )
virtual

Definition at line 20 of file ByteEventTracker.cpp.

References drainByteEvents().

Referenced by proxygen::ByteEventTracker::Callback::~Callback().

20  {
22 }
virtual size_t drainByteEvents()
proxygen::ByteEventTracker::ByteEventTracker ( Callback callback)
inlineexplicit

Definition at line 41 of file ByteEventTracker.h.

References absorb().

41 : callback_(callback) {}

Member Function Documentation

void proxygen::ByteEventTracker::absorb ( ByteEventTracker &&  other)
virtual

Assumes the byte events of another ByteEventTracker that this object is replacing.

Definition at line 24 of file ByteEventTracker.cpp.

References byteEvents_, and folly::gen::move.

Referenced by ByteEventTracker().

24  {
25  byteEvents_ = std::move(other.byteEvents_);
26 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::IntrusiveList< ByteEvent,&ByteEvent::listHook > byteEvents_
virtual void proxygen::ByteEventTracker::addAckByteEvent ( uint64_t  ,
HTTPTransaction  
)
inlinevirtual

The base ByteEventTracker cannot track acks.

Definition at line 81 of file ByteEventTracker.h.

81 {}
void proxygen::ByteEventTracker::addFirstBodyByteEvent ( uint64_t  offset,
HTTPTransaction txn 
)

Definition at line 136 of file ByteEventTracker.cpp.

References byteEvents_, and proxygen::ByteEvent::FIRST_BYTE.

Referenced by proxygen::MockByteEventTracker::MockByteEventTracker(), and setCallback().

137  {
138  byteEvents_.push_back(
139  *new TransactionByteEvent(
140  offset, ByteEvent::FIRST_BYTE,
141  txn));
142 }
folly::IntrusiveList< ByteEvent,&ByteEvent::listHook > byteEvents_
void proxygen::ByteEventTracker::addFirstHeaderByteEvent ( uint64_t  offset,
HTTPTransaction txn 
)
virtual

Definition at line 144 of file ByteEventTracker.cpp.

References byteEvents_, and proxygen::ByteEvent::FIRST_HEADER_BYTE.

Referenced by proxygen::MockByteEventTracker::MockByteEventTracker(), and setCallback().

145  {
146  // onWriteSuccess() is called after the entire header has been written.
147  // It does not catch partial write case.
148  byteEvents_.push_back(
149  *new TransactionByteEvent(offset,
151  txn));
152 }
folly::IntrusiveList< ByteEvent,&ByteEvent::listHook > byteEvents_
void proxygen::ByteEventTracker::addLastByteEvent ( HTTPTransaction txn,
uint64_t  byteNo 
)
virtualnoexcept

Definition at line 89 of file ByteEventTracker.cpp.

References byteEvents_, and proxygen::ByteEvent::LAST_BYTE.

Referenced by proxygen::HTTPSessionBase::handleLastByteEvents(), proxygen::MockByteEventTracker::MockByteEventTracker(), and setCallback().

91  {
92  VLOG(5) << " adding last byte event for " << byteNo;
93  TransactionByteEvent* event = new TransactionByteEvent(
94  byteNo, ByteEvent::LAST_BYTE, txn);
95  byteEvents_.push_back(*event);
96 }
folly::IntrusiveList< ByteEvent,&ByteEvent::listHook > byteEvents_
void proxygen::ByteEventTracker::addPingByteEvent ( size_t  pingSize,
TimePoint  timestamp,
uint64_t  bytesScheduled 
)

The following methods add byte events for tracking

Definition at line 107 of file ByteEventTracker.cpp.

References byteEvents_, i, and uint64_t.

Referenced by proxygen::MockByteEventTracker::MockByteEventTracker(), and setCallback().

109  {
110  // register a byte event on ping reply sent, and adjust the byteOffset_
111  // for others by one ping size
112  uint64_t offset = bytesScheduled + pingSize;
113  auto i = byteEvents_.rbegin();
114  for (; i != byteEvents_.rend(); ++i) {
115  if (i->byteOffset_ > bytesScheduled) {
116  VLOG(5) << "pushing back ByteEvent from " << *i << " to "
117  << ByteEvent(i->byteOffset_ + pingSize, i->eventType_);
118  i->byteOffset_ += pingSize;
119  } else {
120  break; // the rest of the events are already scheduled
121  }
122  }
123 
124  ByteEvent* be = new PingByteEvent(offset, timestamp);
125  if (i == byteEvents_.rend()) {
126  byteEvents_.push_front(*be);
127  } else if (i == byteEvents_.rbegin()) {
128  byteEvents_.push_back(*be);
129  } else {
130  --i;
131  CHECK_GT(i->byteOffset_, bytesScheduled);
132  byteEvents_.insert(i.base(), *be);
133  }
134 }
folly::IntrusiveList< ByteEvent,&ByteEvent::listHook > byteEvents_
void proxygen::ByteEventTracker::addTrackedByteEvent ( HTTPTransaction txn,
uint64_t  byteNo 
)
virtualnoexcept

Definition at line 98 of file ByteEventTracker.cpp.

References byteEvents_, and proxygen::ByteEvent::TRACKED_BYTE.

Referenced by proxygen::MockByteEventTracker::MockByteEventTracker(), and setCallback().

100  {
101  VLOG(5) << " adding tracked byte event for " << byteNo;
102  TransactionByteEvent* event = new TransactionByteEvent(
103  byteNo, ByteEvent::TRACKED_BYTE, txn);
104  byteEvents_.push_back(*event);
105 }
folly::IntrusiveList< ByteEvent,&ByteEvent::listHook > byteEvents_
size_t proxygen::ByteEventTracker::drainByteEvents ( )
virtual

drainByteEvents should be called to clear out any pending events holding transactions when processByteEvents will no longer be called

Definition at line 79 of file ByteEventTracker.cpp.

References byteEvents_.

Referenced by proxygen::MockByteEventTracker::MockByteEventTracker(), setCallback(), and ~ByteEventTracker().

79  {
80  size_t numEvents = 0;
81  // everything is dead from here on, let's just drop all extra refs to txns
82  while (!byteEvents_.empty()) {
83  delete &byteEvents_.front();
84  ++numEvents;
85  }
86  return numEvents;
87 }
folly::IntrusiveList< ByteEvent,&ByteEvent::listHook > byteEvents_
virtual void proxygen::ByteEventTracker::eomEventProcessed ( )
inlineprotectedvirtual

Definition at line 102 of file ByteEventTracker.h.

Referenced by processByteEvents().

102 {}
virtual uint64_t proxygen::ByteEventTracker::preSend ( bool *  ,
bool *  ,
uint64_t   
)
inlinevirtual

HTTPSession uses preSend to truncate writes on an eom boundary. In Ack-tracking ByteEventTracker's, this should exmaine pending byte events and return the number of bytes until the next last byte event, or 0 if none are pending. If non-zero is returned then eom may be set to indicate ack tracking is requested.

Definition at line 91 of file ByteEventTracker.h.

Referenced by proxygen::MockByteEventTracker::MockByteEventTracker().

92  {
93  return 0;
94  }
bool proxygen::ByteEventTracker::processByteEvents ( std::shared_ptr< ByteEventTracker self,
uint64_t  bytesWritten 
)
virtual

processByteEvents is called whenever the transport has accepted more bytes. bytesWritten is the number of bytes written to the transport over its lifetime.

Definition at line 31 of file ByteEventTracker.cpp.

References byteEvents_, callback_, eomEventProcessed(), proxygen::ByteEvent::FIRST_BYTE, proxygen::ByteEvent::FIRST_HEADER_BYTE, int64_t, proxygen::ByteEvent::LAST_BYTE, proxygen::ByteEventTracker::Callback::onLastByteEvent(), proxygen::ByteEventTracker::Callback::onPingReplyLatency(), proxygen::ByteEvent::PING_REPLY_SENT, and proxygen::ByteEvent::TRACKED_BYTE.

Referenced by proxygen::MockByteEventTracker::MockByteEventTracker(), and setCallback().

32  {
33  bool advanceEOM = false;
34 
35  while (!byteEvents_.empty() &&
36  (byteEvents_.front().byteOffset_ <= bytesWritten)) {
37  ByteEvent& event = byteEvents_.front();
38  int64_t latency;
39  auto txn = event.getTransaction();
40 
41  switch (event.eventType_) {
43  txn->onEgressHeaderFirstByte();
44  break;
46  txn->onEgressBodyFirstByte();
47  break;
49  txn->onEgressBodyLastByte();
50  if (callback_) {
51  callback_->onLastByteEvent(txn, event.byteOffset_, event.eomTracked_);
52  }
53  advanceEOM = true;
54  break;
56  txn->onEgressTrackedByte();
57  break;
59  latency = event.getLatency();
60  if (callback_) {
61  callback_->onPingReplyLatency(latency);
62  }
63  break;
64  }
65 
66  VLOG(5) << " removing ByteEvent " << event;
67  // explicitly remove from the list, in case delete event triggers a
68  // callback that would absorb this ByteEventTracker.
69  event.listHook.unlink();
70  delete &event;
71  }
72 
73  if (advanceEOM) {
75  }
76  return self.use_count() == 1;
77 }
virtual void onLastByteEvent(HTTPTransaction *txn, uint64_t offset, bool eomTracked) noexcept=0
virtual void onPingReplyLatency(int64_t latency) noexcept=0
folly::IntrusiveList< ByteEvent,&ByteEvent::listHook > byteEvents_
virtual void proxygen::ByteEventTracker::setTTLBAStats ( TTLBAStats )
inlinevirtual

Definition at line 96 of file ByteEventTracker.h.

96 {}

Member Data Documentation

Callback* proxygen::ByteEventTracker::callback_
protected

Definition at line 104 of file ByteEventTracker.h.

Referenced by processByteEvents(), and setCallback().


The documentation for this class was generated from the following files: