proxygen
folly::AsyncSocket::BytesWriteRequest Class Reference
Inheritance diagram for folly::AsyncSocket::BytesWriteRequest:
folly::AsyncSocket::WriteRequest

Public Member Functions

void destroy () override
 
WriteResult performWrite () override
 
bool isComplete () override
 
void consume () override
 
- Public Member Functions inherited from folly::AsyncSocket::WriteRequest
 WriteRequest (AsyncSocket *socket, WriteCallback *callback)
 
virtual void start ()
 
WriteRequestgetNext () const
 
WriteCallbackgetCallback () const
 
uint32_t getTotalBytesWritten () const
 
void append (WriteRequest *next)
 
void fail (const char *fn, const AsyncSocketException &ex)
 
void bytesWritten (size_t count)
 

Static Public Member Functions

static BytesWriteRequestnewRequest (AsyncSocket *socket, WriteCallback *callback, const iovec *ops, uint32_t opCount, uint32_t partialWritten, uint32_t bytesWritten, unique_ptr< IOBuf > &&ioBuf, WriteFlags flags)
 

Private Member Functions

 BytesWriteRequest (AsyncSocket *socket, WriteCallback *callback, const struct iovec *ops, uint32_t opCount, uint32_t partialBytes, uint32_t bytesWritten, unique_ptr< IOBuf > &&ioBuf, WriteFlags flags)
 
 ~BytesWriteRequest () override=default
 
const struct iovec * getOps () const
 
uint32_t getOpCount () const
 

Private Attributes

uint32_t opCount_
 number of entries in writeOps_ More...
 
uint32_t opIndex_
 current index into writeOps_ More...
 
WriteFlags flags_
 set for WriteFlags More...
 
unique_ptr< IOBufioBuf_
 underlying IOBuf, or nullptr if N/A More...
 
uint32_t opsWritten_
 complete ops written More...
 
uint32_t partialBytes_
 partial bytes of incomplete op written More...
 
ssize_t bytesWritten_
 bytes written altogether More...
 
struct iovec writeOps_ []
 write operation(s) list More...
 

Additional Inherited Members

- Protected Member Functions inherited from folly::AsyncSocket::WriteRequest
virtual ~WriteRequest ()
 
- Protected Attributes inherited from folly::AsyncSocket::WriteRequest
AsyncSocketsocket_
 parent socket More...
 
WriteRequestnext_ {nullptr}
 pointer to next WriteRequest More...
 
WriteCallbackcallback_
 completion callback More...
 
uint32_t totalBytesWritten_ {0}
 total bytes written More...
 

Detailed Description

Definition at line 81 of file AsyncSocket.cpp.

Constructor & Destructor Documentation

folly::AsyncSocket::BytesWriteRequest::BytesWriteRequest ( AsyncSocket socket,
WriteCallback callback,
const struct iovec *  ops,
uint32_t  opCount,
uint32_t  partialBytes,
uint32_t  bytesWritten,
unique_ptr< IOBuf > &&  ioBuf,
WriteFlags  flags 
)
inlineprivate

Definition at line 179 of file AsyncSocket.cpp.

References opCount_, writeOps_, and ~BytesWriteRequest().

Referenced by newRequest().

188  : AsyncSocket::WriteRequest(socket, callback),
189  opCount_(opCount),
190  opIndex_(0),
191  flags_(flags),
192  ioBuf_(std::move(ioBuf)),
193  opsWritten_(0),
194  partialBytes_(partialBytes),
196  memcpy(writeOps_, ops, sizeof(*ops) * opCount_);
197  }
flags
Definition: http_parser.h:127
uint32_t opCount_
number of entries in writeOps_
WriteFlags flags_
set for WriteFlags
ssize_t bytesWritten_
bytes written altogether
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
struct iovec writeOps_[]
write operation(s) list
uint32_t opsWritten_
complete ops written
const int ops
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
unique_ptr< IOBuf > ioBuf_
underlying IOBuf, or nullptr if N/A
uint32_t opIndex_
current index into writeOps_
void bytesWritten(size_t count)
Definition: AsyncSocket.h:924
uint32_t partialBytes_
partial bytes of incomplete op written
folly::AsyncSocket::BytesWriteRequest::~BytesWriteRequest ( )
overrideprivatedefault

Referenced by BytesWriteRequest(), and destroy().

Member Function Documentation

void folly::AsyncSocket::BytesWriteRequest::consume ( )
inlineoverridevirtual

Implements folly::AsyncSocket::WriteRequest.

Definition at line 151 of file AsyncSocket.cpp.

References bytesWritten_, flags_, i, ioBuf_, folly::AsyncSocket::isZeroCopyRequest(), opCount_, opIndex_, opsWritten_, partialBytes_, folly::AsyncSocket::WriteRequest::socket_, folly::AsyncSocket::WriteRequest::totalBytesWritten_, uint32_t, uint8_t, and writeOps_.

151  {
152  // Advance opIndex_ forward by opsWritten_
154  assert(opIndex_ < opCount_);
155 
157  // If we've finished writing any IOBufs, release them
158  if (ioBuf_) {
159  for (uint32_t i = opsWritten_; i != 0; --i) {
160  assert(ioBuf_);
161  ioBuf_ = ioBuf_->pop();
162  }
163  }
164  }
165 
166  // Move partialBytes_ forward into the current iovec buffer
167  struct iovec* currentOp = writeOps_ + opIndex_;
168  assert((partialBytes_ < currentOp->iov_len) || (currentOp->iov_len == 0));
169  currentOp->iov_base =
170  reinterpret_cast<uint8_t*>(currentOp->iov_base) + partialBytes_;
171  currentOp->iov_len -= partialBytes_;
172 
173  // Increment the totalBytesWritten_ count by bytesWritten_;
174  assert(bytesWritten_ >= 0);
176  }
uint32_t opCount_
number of entries in writeOps_
bool isZeroCopyRequest(WriteFlags flags)
WriteFlags flags_
set for WriteFlags
ssize_t bytesWritten_
bytes written altogether
AsyncSocket * socket_
parent socket
Definition: AsyncSocket.h:933
struct iovec writeOps_[]
write operation(s) list
uint32_t opsWritten_
complete ops written
unique_ptr< IOBuf > ioBuf_
underlying IOBuf, or nullptr if N/A
uint32_t opIndex_
current index into writeOps_
uint32_t totalBytesWritten_
total bytes written
Definition: AsyncSocket.h:936
uint32_t partialBytes_
partial bytes of incomplete op written
void folly::AsyncSocket::BytesWriteRequest::destroy ( )
inlineoverridevirtual

Implements folly::AsyncSocket::WriteRequest.

Definition at line 112 of file AsyncSocket.cpp.

References bm::free(), and ~BytesWriteRequest().

112  {
113  this->~BytesWriteRequest();
114  free(this);
115  }
void free()
uint32_t folly::AsyncSocket::BytesWriteRequest::getOpCount ( ) const
inlineprivate

Definition at line 207 of file AsyncSocket.cpp.

References opCount_, and opIndex_.

Referenced by isComplete(), and performWrite().

207  {
208  assert(opCount_ > opIndex_);
209  return opCount_ - opIndex_;
210  }
uint32_t opCount_
number of entries in writeOps_
uint32_t opIndex_
current index into writeOps_
const struct iovec* folly::AsyncSocket::BytesWriteRequest::getOps ( ) const
inlineprivate

Definition at line 202 of file AsyncSocket.cpp.

References opCount_, opIndex_, and writeOps_.

Referenced by performWrite().

202  {
203  assert(opCount_ > opIndex_);
204  return writeOps_ + opIndex_;
205  }
uint32_t opCount_
number of entries in writeOps_
struct iovec writeOps_[]
write operation(s) list
uint32_t opIndex_
current index into writeOps_
bool folly::AsyncSocket::BytesWriteRequest::isComplete ( )
inlineoverridevirtual

Implements folly::AsyncSocket::WriteRequest.

Definition at line 147 of file AsyncSocket.cpp.

References getOpCount(), and opsWritten_.

Referenced by performWrite().

147  {
148  return opsWritten_ == getOpCount();
149  }
uint32_t opsWritten_
complete ops written
static BytesWriteRequest* folly::AsyncSocket::BytesWriteRequest::newRequest ( AsyncSocket socket,
WriteCallback callback,
const iovec *  ops,
uint32_t  opCount,
uint32_t  partialWritten,
uint32_t  bytesWritten,
unique_ptr< IOBuf > &&  ioBuf,
WriteFlags  flags 
)
inlinestatic

Definition at line 83 of file AsyncSocket.cpp.

References BytesWriteRequest(), and folly::gen::move.

Referenced by folly::AsyncSocket::writeImpl().

91  {
92  assert(opCount > 0);
93  // Since we put a variable size iovec array at the end
94  // of each BytesWriteRequest, we have to manually allocate the memory.
95  void* buf =
96  malloc(sizeof(BytesWriteRequest) + (opCount * sizeof(struct iovec)));
97  if (buf == nullptr) {
98  throw std::bad_alloc();
99  }
100 
101  return new (buf) BytesWriteRequest(
102  socket,
103  callback,
104  ops,
105  opCount,
106  partialWritten,
107  bytesWritten,
108  std::move(ioBuf),
109  flags);
110  }
flags
Definition: http_parser.h:127
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
BytesWriteRequest(AsyncSocket *socket, WriteCallback *callback, const struct iovec *ops, uint32_t opCount, uint32_t partialBytes, uint32_t bytesWritten, unique_ptr< IOBuf > &&ioBuf, WriteFlags flags)
const int ops
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
void bytesWritten(size_t count)
Definition: AsyncSocket.h:924
WriteResult folly::AsyncSocket::BytesWriteRequest::performWrite ( )
inlineoverridevirtual

Implements folly::AsyncSocket::WriteRequest.

Definition at line 117 of file AsyncSocket.cpp.

References folly::AsyncSocket::addZeroCopyBuf(), folly::AsyncSocket::adjustZeroCopyFlags(), bytesWritten_, folly::AsyncSocket::containsZeroCopyBuf(), folly::CORK, flags_, folly::AsyncSocket::WriteRequest::getNext(), getOpCount(), getOps(), folly::AsyncSocket::getZeroCopy(), ioBuf_, isComplete(), folly::AsyncSocket::isZeroCopyRequest(), folly::gen::move, opsWritten_, partialBytes_, folly::AsyncSocket::performWrite(), folly::AsyncSocket::setZeroCopyBuf(), and folly::AsyncSocket::WriteRequest::socket_.

117  {
118  WriteFlags writeFlags = flags_;
119  if (getNext() != nullptr) {
120  writeFlags |= WriteFlags::CORK;
121  }
122 
123  socket_->adjustZeroCopyFlags(writeFlags);
124 
125  auto writeResult = socket_->performWrite(
126  getOps(), getOpCount(), writeFlags, &opsWritten_, &partialBytes_);
127  bytesWritten_ = writeResult.writeReturn > 0 ? writeResult.writeReturn : 0;
128  if (bytesWritten_) {
129  if (socket_->isZeroCopyRequest(writeFlags)) {
130  if (isComplete()) {
132  } else {
133  socket_->addZeroCopyBuf(ioBuf_.get());
134  }
135  } else {
136  // this happens if at least one of the prev requests were sent
137  // with zero copy but not the last one
138  if (isComplete() && socket_->getZeroCopy() &&
141  }
142  }
143  }
144  return writeResult;
145  }
void setZeroCopyBuf(std::unique_ptr< folly::IOBuf > &&buf)
const struct iovec * getOps() const
bool isZeroCopyRequest(WriteFlags flags)
bool containsZeroCopyBuf(folly::IOBuf *ptr)
WriteFlags flags_
set for WriteFlags
virtual WriteResult performWrite(const iovec *vec, uint32_t count, WriteFlags flags, uint32_t *countWritten, uint32_t *partialWritten)
ssize_t bytesWritten_
bytes written altogether
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
WriteRequest * getNext() const
Definition: AsyncSocket.h:903
AsyncSocket * socket_
parent socket
Definition: AsyncSocket.h:933
uint32_t opsWritten_
complete ops written
unique_ptr< IOBuf > ioBuf_
underlying IOBuf, or nullptr if N/A
void addZeroCopyBuf(std::unique_ptr< folly::IOBuf > &&buf)
bool getZeroCopy() const
Definition: AsyncSocket.h:504
void adjustZeroCopyFlags(folly::WriteFlags &flags)
uint32_t partialBytes_
partial bytes of incomplete op written

Member Data Documentation

ssize_t folly::AsyncSocket::BytesWriteRequest::bytesWritten_
private

bytes written altogether

Definition at line 220 of file AsyncSocket.cpp.

Referenced by consume(), and performWrite().

WriteFlags folly::AsyncSocket::BytesWriteRequest::flags_
private

set for WriteFlags

Definition at line 214 of file AsyncSocket.cpp.

Referenced by consume(), and performWrite().

unique_ptr<IOBuf> folly::AsyncSocket::BytesWriteRequest::ioBuf_
private

underlying IOBuf, or nullptr if N/A

Definition at line 215 of file AsyncSocket.cpp.

Referenced by consume(), and performWrite().

uint32_t folly::AsyncSocket::BytesWriteRequest::opCount_
private

number of entries in writeOps_

Definition at line 212 of file AsyncSocket.cpp.

Referenced by BytesWriteRequest(), consume(), getOpCount(), and getOps().

uint32_t folly::AsyncSocket::BytesWriteRequest::opIndex_
private

current index into writeOps_

Definition at line 213 of file AsyncSocket.cpp.

Referenced by consume(), getOpCount(), and getOps().

uint32_t folly::AsyncSocket::BytesWriteRequest::opsWritten_
private

complete ops written

Definition at line 218 of file AsyncSocket.cpp.

Referenced by consume(), isComplete(), and performWrite().

uint32_t folly::AsyncSocket::BytesWriteRequest::partialBytes_
private

partial bytes of incomplete op written

Definition at line 219 of file AsyncSocket.cpp.

Referenced by consume(), and performWrite().

struct iovec folly::AsyncSocket::BytesWriteRequest::writeOps_[]
private

write operation(s) list

Definition at line 222 of file AsyncSocket.cpp.

Referenced by BytesWriteRequest(), consume(), and getOps().


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