folly::AsyncSocket::WriteRequestTag

Sometimes SendMsgParamsCallback needs to send different ancillary data for different writes, for example when sending FDs over Unix sockets.

Synopsis

Declared in <folly/io/async/AsyncSocket.h>

struct WriteRequestTag;

Description

This opaque type acts as the key to match writeChain calls with getAncillaryData() and corresponding wroteBytes() calls. It wraps IOBuf*, and implements equality, hashing, and ostream writes for debugging.

Important usage notes:

  • Even though WriteRequestTag never dereferences the pointer, it is still INCORRECT to use it after the write is over, whether or not the IOBuf had been destructed, because the same pointer could now refer to new, different data that is being written (see getReleaseIOBufCallback for the mechanism).

  • Therefore, if you store a WriteRequestTag, you must remove it whenever a write is complete. This can be done either in WriteCallback::{writeErr,writeSuccess}, or by inheriting from AsyncSocket::releaseIOBuf, or by adding a new method SendMsgParamsCallback::onReleaseIOBuf.

  • Not all child classes support write tagging. Notably, we removed the AsyncSSLSocket implementation since it added complexity and was not used. Breadcrumbs are in bioWrite, or rev hash 95df2ce7c98a.

  • The EmptyDummy constructor is for tests, or marking empty tags. SendMsgParamsCallback methods can also be called with an empty tag if the write is not submitted via writeChain.

Types

NameDescription
EmptyDummy Tag type marking an empty tag, used for tests or unsubmitted writes.

Member Functions

NameDescription
WriteRequestTag [constructor]Constructors
empty Check whether the tag is empty.
operator== Compares two tags for equality by wrapped pointer.

Friends

NameDescription
folly::operator<<Writes a textual representation of the tag to a stream.
std::hash<folly::AsyncSocket::WriteRequestTag>Hash specialization for AsyncSocket::WriteRequestTag.