proxygen
ByteEvents.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
12 #include <folly/IntrusiveList.h>
16 
17 namespace proxygen {
18 
19 class ByteEvent {
20  public:
21  enum EventType {
27  };
28 
29  ByteEvent(uint64_t byteOffset, EventType eventType)
30  : eventType_(eventType), eomTracked_(0), byteOffset_(byteOffset) {}
31  virtual ~ByteEvent() {}
32  virtual HTTPTransaction* getTransaction() { return nullptr; }
33  virtual int64_t getLatency() { return -1; }
34 
36  EventType eventType_:3; // packed w/ byteOffset_
37  size_t eomTracked_:1;
38  uint64_t byteOffset_:(8*sizeof(uint64_t)-4);
39 };
40 
41 std::ostream& operator<<(std::ostream& os, const ByteEvent& txn);
42 
44  public:
46  EventType eventType,
47  HTTPTransaction* txn)
48  : ByteEvent(byteNo, eventType), txn_(txn) {
49  txn_->incrementPendingByteEvents();
50  }
51 
53  txn_->decrementPendingByteEvents();
54  }
55 
57  return txn_;
58  }
59 
61 };
62 
64  : public AsyncTimeoutSet::Callback {
65  public:
70  class Callback {
71  public:
72  virtual ~Callback() {}
73  virtual void ackTimeoutExpired(uint64_t byteNo) noexcept = 0;
74  };
75 
76  AckTimeout(Callback* callback, uint64_t byteNo)
77  : callback_(callback), byteNo_(byteNo) {}
78 
79  void timeoutExpired() noexcept override {
80  callback_->ackTimeoutExpired(byteNo_);
81  }
82 
83  private:
86 };
87 
89  public:
91  uint64_t byteNo,
92  EventType eventType,
93  HTTPTransaction* txn)
94  : TransactionByteEvent(byteNo, eventType, txn),
95  timeout(callback, byteNo) {}
96 
98 };
99 
100 class PingByteEvent : public ByteEvent {
101  public:
102  PingByteEvent(uint64_t byteOffset, TimePoint pingRequestReceivedTime)
103  : ByteEvent(byteOffset, PING_REPLY_SENT),
104  pingRequestReceivedTime_(pingRequestReceivedTime) {}
105 
106  int64_t getLatency() override;
107 
109 };
110 
111 } // proxygen
folly::IntrusiveListHook listHook
Definition: ByteEvents.h:35
Callback * callback_
Definition: ByteEvents.h:84
ByteEvent(uint64_t byteOffset, EventType eventType)
Definition: ByteEvents.h:29
std::ostream & operator<<(std::ostream &os, const HeaderTable &table)
EventType eventType_
Definition: ByteEvents.h:36
virtual ~ByteEvent()
Definition: ByteEvents.h:31
AckTimeout(Callback *callback, uint64_t byteNo)
Definition: ByteEvents.h:76
requires E e noexcept(noexcept(s.error(std::move(e))))
PingByteEvent(uint64_t byteOffset, TimePoint pingRequestReceivedTime)
Definition: ByteEvents.h:102
TransactionByteEvent(uint64_t byteNo, EventType eventType, HTTPTransaction *txn)
Definition: ByteEvents.h:45
boost::intrusive::list_member_hook< boost::intrusive::link_mode< boost::intrusive::auto_unlink >> IntrusiveListHook
Definition: IntrusiveList.h:32
virtual HTTPTransaction * getTransaction()
Definition: ByteEvents.h:32
virtual int64_t getLatency()
Definition: ByteEvents.h:33
uint64_t byteOffset_
Definition: ByteEvents.h:38
SteadyClock::time_point TimePoint
Definition: Time.h:25
HTTPTransaction * getTransaction() override
Definition: ByteEvents.h:56
TimePoint pingRequestReceivedTime_
Definition: ByteEvents.h:108
AckByteEvent(AckTimeout::Callback *callback, uint64_t byteNo, EventType eventType, HTTPTransaction *txn)
Definition: ByteEvents.h:90
HTTPTransaction * txn_
Definition: ByteEvents.h:60
folly::Function< void()> callback_
void timeoutExpired() noexceptoverride
Definition: ByteEvents.h:79