proxygen
folly::AsyncSocket::SendMsgParamsCallback Class Reference

#include <AsyncSocket.h>

Inheritance diagram for folly::AsyncSocket::SendMsgParamsCallback:
folly::SendMsgParamsCallbackBase TestSendMsgParamsCallback folly::SendMsgFlagsCallback folly::SendMsgDataCallback

Public Member Functions

virtual ~SendMsgParamsCallback ()=default
 
int getFlags (folly::WriteFlags flags, bool zeroCopyEnabled) noexcept
 
virtual void getAncillaryData (folly::WriteFlags, void *) noexcept
 
virtual uint32_t getAncillaryDataSize (folly::WriteFlags) noexcept
 

Static Public Attributes

static const size_t maxAncillaryDataSize {0x5000}
 

Private Member Functions

virtual int getFlagsImpl (folly::WriteFlags, int defaultFlags)
 
int getDefaultFlags (folly::WriteFlags flags, bool zeroCopyEnabled) noexcept
 

Detailed Description

Definition at line 143 of file AsyncSocket.h.

Constructor & Destructor Documentation

virtual folly::AsyncSocket::SendMsgParamsCallback::~SendMsgParamsCallback ( )
virtualdefault

Member Function Documentation

virtual void folly::AsyncSocket::SendMsgParamsCallback::getAncillaryData ( folly::WriteFlags  ,
void *   
)
inlinevirtualnoexcept

getAncillaryData() will be invoked to initialize ancillary data buffer referred by "msg_control" field of msghdr structure passed to sendmsg() system call. The function assumes that the size of buffer is not smaller than the value returned by getAncillaryDataSize() method for the same combination of flags.

Parameters
flagsWrite flags requested for the given write operation
dataPointer to ancillary data buffer to initialize.

Reimplemented in TestSendMsgParamsCallback, folly::SendMsgDataCallback, and folly::SendMsgParamsCallbackBase.

Definition at line 170 of file AsyncSocket.h.

Referenced by folly::SendMsgParamsCallbackBase::getAncillaryData(), folly::SendMsgDataCallback::getAncillaryData(), and folly::AsyncSocket::performWrite().

172  {}
virtual uint32_t folly::AsyncSocket::SendMsgParamsCallback::getAncillaryDataSize ( folly::WriteFlags  )
inlinevirtualnoexcept

getAncillaryDataSize() will be invoked to retrieve the size of ancillary data buffer which should be passed to sendmsg() system call

Parameters
flagsWrite flags requested for the given write operation

Reimplemented in TestSendMsgParamsCallback, folly::SendMsgDataCallback, and folly::SendMsgParamsCallbackBase.

Definition at line 180 of file AsyncSocket.h.

Referenced by folly::SendMsgParamsCallbackBase::getAncillaryDataSize(), folly::SendMsgDataCallback::getAncillaryDataSize(), and folly::AsyncSocket::performWrite().

181  {
182  return 0;
183  }
int folly::AsyncSocket::SendMsgParamsCallback::getDefaultFlags ( folly::WriteFlags  flags,
bool  zeroCopyEnabled 
)
privatenoexcept

getDefaultFlags() will be invoked by getFlags(folly::WriteFlags flags) to retrieve the default set of flags, and pass them to getFlagsImpl(...)

Parameters
flagsWrite flags requested for the given write operation

Definition at line 225 of file AsyncSocket.cpp.

References folly::CORK, folly::EOR, folly::isSet(), MSG_ZEROCOPY, folly::netops::setsockopt(), and folly::WRITE_MSG_ZEROCOPY.

227  {
228  int msg_flags = MSG_DONTWAIT;
229 
230 #ifdef MSG_NOSIGNAL // Linux-only
231  msg_flags |= MSG_NOSIGNAL;
232 #ifdef MSG_MORE
233  if (isSet(flags, WriteFlags::CORK)) {
234  // MSG_MORE tells the kernel we have more data to send, so wait for us to
235  // give it the rest of the data rather than immediately sending a partial
236  // frame, even when TCP_NODELAY is enabled.
237  msg_flags |= MSG_MORE;
238  }
239 #endif // MSG_MORE
240 #endif // MSG_NOSIGNAL
241  if (isSet(flags, WriteFlags::EOR)) {
242  // marks that this is the last byte of a record (response)
243  msg_flags |= MSG_EOR;
244  }
245 
246  if (zeroCopyEnabled && isSet(flags, WriteFlags::WRITE_MSG_ZEROCOPY)) {
247  msg_flags |= MSG_ZEROCOPY;
248  }
249 
250  return msg_flags;
251 }
flags
Definition: http_parser.h:127
#define MSG_ZEROCOPY
Definition: NetOps.h:55
bool isSet(WriteFlags a, WriteFlags b)
int folly::AsyncSocket::SendMsgParamsCallback::getFlags ( folly::WriteFlags  flags,
bool  zeroCopyEnabled 
)
inlinenoexcept

getFlags() will be invoked to retrieve the desired flags to be passed to sendmsg() system call. This method was intentionally declared non-virtual, so there is no way to override it. Instead feel free to override getFlagsImpl(flags, defaultFlags) method instead, and enjoy the convenience of defaultFlags passed there.

Parameters
flagsWrite flags requested for the given write operation

Definition at line 156 of file AsyncSocket.h.

Referenced by folly::SendMsgParamsCallbackBase::getFlagsImpl(), folly::SendMsgFlagsCallback::getFlagsImpl(), and folly::AsyncSocket::performWrite().

156  {
157  return getFlagsImpl(flags, getDefaultFlags(flags, zeroCopyEnabled));
158  }
flags
Definition: http_parser.h:127
virtual int getFlagsImpl(folly::WriteFlags, int defaultFlags)
Definition: AsyncSocket.h:201
int getDefaultFlags(folly::WriteFlags flags, bool zeroCopyEnabled) noexcept
virtual int folly::AsyncSocket::SendMsgParamsCallback::getFlagsImpl ( folly::WriteFlags  ,
int  defaultFlags 
)
inlineprivatevirtual

getFlagsImpl() will be invoked by getFlags(folly::WriteFlags flags) method to retrieve the flags to be passed to sendmsg() system call. SendMsgParamsCallback::getFlags() is calling this method, and returns its results directly to the caller in AsyncSocket. Classes inheriting from SendMsgParamsCallback are welcome to override this method to force SendMsgParamsCallback to return its own set of flags.

Parameters
flagsWrite flags requested for the given write operation
defaultflagsA set of message flags returned by getDefaultFlags() method for the given "flags" mask.

Reimplemented in TestSendMsgParamsCallback, folly::SendMsgFlagsCallback, and folly::SendMsgParamsCallbackBase.

Definition at line 201 of file AsyncSocket.h.

References folly::AsyncSocket::AsyncSocket(), folly::pushmi::__adl::noexcept(), folly::AsyncSocket::setShutdownSocketSet(), string, uint16_t, and uint32_t.

201  {
202  return defaultFlags;
203  }

Member Data Documentation

const size_t folly::AsyncSocket::SendMsgParamsCallback::maxAncillaryDataSize {0x5000}
static

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