folly::SocketFds

Represents an ordered collection of file descriptors. This union type either contains: - FDs to be sent on a socket -- with shared ownership, since the sender may still need them, OR - FDs just received, with sole ownership.

Synopsis

Declared in <folly/io/async/fdsock/SocketFds.h>

class SocketFds final

Description

This hides the variant of containers behind a unique_ptr so that the normal / fast path, which is not passing FDs, is as light as possible, adding just 8 bytes for a pointer.

== Rationale ==

In order to send FDs over Unix sockets, Thrift plumbs them through a variety of classes. Many of these can be used both for send & receive operations (THeader, StreamPayload, etc).

This is especially useful in regular Thrift request-response handler methods, where the same THeader is used for consuming the received FDs, and sending back FDs with the response -- necessarily in that order.

Type Aliases

NameDescription
Received File descriptors just received, held with sole ownership.
SeqNum Sequence number associating FDs with socket data messages.
ToSend File descriptors to be sent on a socket, held with shared ownership.

Member Functions

NameDescription
SocketFds [constructor]Constructors
operator= Move-assigns from another collection, leaving it empty.
cloneToSendFromOrDfatal Clones the ToSend file descriptors from another collection.
dcheckEmpty Debug-asserts that this collection is empty.
dcheckReceivedOrEmpty Debug-asserts that this collection holds Received FDs or is empty.
dcheckToSendOrEmpty Debug-asserts that this collection holds ToSend FDs or is empty.
empty Returns whether the collection holds no file descriptors.
getFdSocketSeqNum Returns the sequence number associated with this collection.
releaseReceived Releases and returns the received file descriptors.
releaseToSendAndSeqNum Releases the ToSend file descriptors with their sequence number.
setFdSocketSeqNumOnce Attaches a sequence number to this collection, at most once.
size Returns the number of file descriptors in the collection.

Static Data Members

NameDescription
kNoSeqNum Sentinel sequence number meaning that none was set.