Enable observers to request socket timestamps
Summary: D24094832 (https://github.com/facebook/folly/commit/842ecea531e8d6a90559f213be3793f7cd36781b) added `ByteEvent` support to `AsyncSocket`, making it easier to use socket timestamps for SCHED/TX/ACK events. With D24094832 (https://github.com/facebook/folly/commit/842ecea531e8d6a90559f213be3793f7cd36781b): - An application can request socket timestamps by installing an observer with `ByteEvents` enabled, and then writing to the socket with a relevant timestamping flag (e.g., `TIMESTAMP_TX`, `TIMESTAMP_ACK`). - Timestamps are delivered to the observer via the `byteEvent` callback. This diff enables *observers* to request socket timestamping by interposing between the application and the socket by way of the `prewrite` event: - Each time bytes from the application are about to be written to the underlying raw socket / FD, `AsyncSocket` will give observers an opportunity to request timestamping via a `prewrite` event. - If an observer wishes to request timestamping, it can return a `PrewriteRequest` with information about the `WriteFlags` to add. - If an observer wishes to timestamp a specific byte (first byte, every 1000th byte, etc.), it can request this with the `maybeOffsetToSplitWrite` field — socket timestamp requests apply to the *last byte* in the buffer being written, and thus if an observer wants to timestamp a specific byte, the buffer must be split so that the byte to timestamp is the final byte. The `AsyncSocket` implementation handles this split on behalf of the observer and adds `WriteFlags::CORK` (triggering `MSG_MORE`) where appropriate. - If multiple observers are attached, `PrewriteRequests` are combined so that all observer needs are satisfied. In addition, `WriteFlags` set by the application and `WriteFlags` set by observers are combined during processing of `PrewriteRequests`. Reviewed By: yfeldblum Differential Revision: D24976575 fbshipit-source-id: 885720173d4a9ceefebc929a86d5e0f10f8889c4
Showing
This source diff could not be displayed because it is too large. You can view the blob instead.
Please register or sign in to comment