proxygen
TestAsyncTransport::WriteEvent Class Reference

#include <TestAsyncTransport.h>

Public Member Functions

proxygen::TimePoint getTime () const
 
const struct iovec * getIoVec () const
 
size_t getCount () const
 

Static Public Member Functions

static std::shared_ptr< WriteEventnewEvent (const struct iovec *vec, size_t count)
 

Private Member Functions

 WriteEvent (proxygen::TimePoint time, size_t count)
 
 ~WriteEvent ()
 

Static Private Member Functions

static void destroyEvent (WriteEvent *event)
 

Private Attributes

proxygen::TimePoint time_
 
size_t count_
 
struct iovec vec_ []
 

Detailed Description

Definition at line 22 of file TestAsyncTransport.h.

Constructor & Destructor Documentation

TestAsyncTransport::WriteEvent::WriteEvent ( proxygen::TimePoint  time,
size_t  count 
)
private

Definition at line 111 of file TestAsyncTransport.cpp.

References count_, and vec_.

Referenced by getCount(), and newEvent().

112  : time_(time),
113  count_(count) {
114  // Initialize all of the iov_base pointers to nullptr. This way we won't free
115  // an uninitialized pointer in the destructor if we fail to allocate any of
116  // the buffers.
117  for (size_t n = 0; n < count_; ++n) {
118  vec_[n].iov_base = nullptr;
119  }
120 }
int * count
std::chrono::nanoseconds time()
TestAsyncTransport::WriteEvent::~WriteEvent ( )
private

Definition at line 122 of file TestAsyncTransport.cpp.

References count_, bm::free(), and vec_.

Referenced by getCount().

122  {
123  for (size_t n = 0; n < count_; ++n) {
124  free(vec_[n].iov_base);
125  }
126 }
void free()

Member Function Documentation

void TestAsyncTransport::WriteEvent::destroyEvent ( WriteEvent event)
staticprivate

Definition at line 159 of file TestAsyncTransport.cpp.

References bm::free().

Referenced by getCount(), and newEvent().

159  {
160  event->~WriteEvent();
161  free(event);
162 }
void free()
size_t TestAsyncTransport::WriteEvent::getCount ( ) const
inline
const struct iovec* TestAsyncTransport::WriteEvent::getIoVec ( ) const
inline

Definition at line 30 of file TestAsyncTransport.h.

References vec_.

30  {
31  return vec_;
32  }
proxygen::TimePoint TestAsyncTransport::WriteEvent::getTime ( ) const
inline

Definition at line 27 of file TestAsyncTransport.h.

References time_.

27  {
28  return time_;
29  }
shared_ptr< TestAsyncTransport::WriteEvent > TestAsyncTransport::WriteEvent::newEvent ( const struct iovec *  vec,
size_t  count 
)
static

Definition at line 129 of file TestAsyncTransport.cpp.

References count, destroyEvent(), proxygen::getCurrentTime(), now(), and WriteEvent().

Referenced by TestAsyncTransport::writev().

130  {
131  size_t bufLen = sizeof(WriteEvent) + (count * sizeof(struct iovec));
132  void* buf = malloc(bufLen);
133  if (buf == nullptr) {
134  throw std::bad_alloc();
135  }
136 
137  auto now = proxygen::getCurrentTime();
138  shared_ptr<WriteEvent> event(new(buf) WriteEvent(now, count),
139  destroyEvent);
140  for (size_t n = 0; n < count; ++n) {
141  size_t len = vec[n].iov_len;
142  event->vec_[n].iov_len = len;
143  if (len == 0) {
144  event->vec_[n].iov_base = nullptr;
145  continue;
146  }
147 
148  event->vec_[n].iov_base = malloc(len);
149  if (event->vec_[n].iov_base == nullptr) {
150  throw std::bad_alloc();
151  }
152  memcpy(event->vec_[n].iov_base, vec[n].iov_base, len);
153  }
154 
155  return event;
156 }
WriteEvent(proxygen::TimePoint time, size_t count)
std::chrono::steady_clock::time_point now()
Definition: Traits.h:588
int * count
std::chrono::time_point< ClockType > getCurrentTime()
Definition: Time.h:41
static void destroyEvent(WriteEvent *event)

Member Data Documentation

size_t TestAsyncTransport::WriteEvent::count_
private

Definition at line 44 of file TestAsyncTransport.h.

Referenced by getCount(), WriteEvent(), and ~WriteEvent().

proxygen::TimePoint TestAsyncTransport::WriteEvent::time_
private

Definition at line 43 of file TestAsyncTransport.h.

Referenced by getTime().

struct iovec TestAsyncTransport::WriteEvent::vec_[]
private

Definition at line 45 of file TestAsyncTransport.h.

Referenced by getIoVec(), WriteEvent(), and ~WriteEvent().


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