virtual void errMessageError(const AsyncSocketException& ex) noexcept = 0;
};
+ class SendMsgParamsCallback {
+ public:
+ virtual ~SendMsgParamsCallback() = default;
+
+ /**
+ * 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.
+ *
+ * @param flags Write flags requested for the given write operation
+ */
+ int getFlags(folly::WriteFlags flags) noexcept {
+ return getFlagsImpl(flags, getDefaultFlags(flags));
+ }
+
+ /**
+ * 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.
+ *
+ * @param flags Write flags requested for the given write operation
+ * @param data Pointer to ancillary data buffer to initialize.
+ */
+ virtual void getAncillaryData(
+ folly::WriteFlags /*flags*/,
+ void* /*data*/) noexcept {}
+
+ /**
+ * getAncillaryDataSize() will be invoked to retrieve the size of
+ * ancillary data buffer which should be passed to ::sendmsg() system call
+ *
+ * @param flags Write flags requested for the given write operation
+ */
+ virtual uint32_t getAncillaryDataSize(folly::WriteFlags /*flags*/)
+ noexcept {
+ return 0;
+ }
+
+ static const size_t maxAncillaryDataSize{0x5000};
+
+ private:
+ /**
+ * 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.
+ *
+ * @param flags Write flags requested for the given write operation
+ * @param defaultflags A set of message flags returned by getDefaultFlags()
+ * method for the given "flags" mask.
+ */
+ virtual int getFlagsImpl(folly::WriteFlags /*flags*/, int defaultFlags) {
+ return defaultFlags;
+ }
+
+ /**
+ * getDefaultFlags() will be invoked by getFlags(folly::WriteFlags flags)
+ * to retrieve the default set of flags, and pass them to getFlagsImpl(...)
+ *
+ * @param flags Write flags requested for the given write operation
+ */
+ int getDefaultFlags(folly::WriteFlags flags) noexcept;
+ };
+
explicit AsyncSocket();
/**
* Create a new unconnected AsyncSocket.
*/
ErrMessageCallback* getErrMessageCallback() const;
+ /**
+ * Set a pointer to SendMsgParamsCallback implementation which
+ * will be used to form ::sendmsg() system call parameters
+ *
+ */
+ void setSendMsgParamCB(SendMsgParamsCallback* callback);
+
+ /**
+ * Get a pointer to SendMsgParamsCallback implementation currently
+ * registered with this socket.
+ *
+ */
+ SendMsgParamsCallback* getSendMsgParamsCB() const;
+
// Read and write methods
void setReadCB(ReadCallback* callback) override;
ReadCallback* getReadCallback() const override;
ConnectCallback* connectCallback_; ///< ConnectCallback
ErrMessageCallback* errMessageCallback_; ///< TimestampCallback
+ SendMsgParamsCallback* ///< Callback for retreaving
+ sendMsgParamCallback_; ///< ::sendmsg() parameters
ReadCallback* readCallback_; ///< ReadCallback
WriteRequest* writeReqHead_; ///< Chain of WriteRequests
WriteRequest* writeReqTail_; ///< End of WriteRequest chain
// socket.
std::unique_ptr<IOBuf> preReceivedData_;
- int8_t readErr_{READ_NO_ERROR}; ///< The read error encountered, if any.
+ int8_t readErr_{READ_NO_ERROR}; ///< The read error encountered, if any
std::chrono::steady_clock::time_point connectStartTime_;
std::chrono::steady_clock::time_point connectEndTime_;