#define SO_NO_TRANSPARENT_TLS 200
#endif
+#if defined __linux__ && !defined SO_NO_TSOCKS
+#define SO_NO_TSOCKS 201
+#endif
+
#ifdef _MSC_VER
// We do a dynamic_cast on this, in
// AsyncTransportWrapper::getUnderlyingTransport so be safe and
* This prevents callers from deleting a AsyncSocket while it is invoking a
* callback.
*/
- virtual void destroy() override;
+ void destroy() override;
/**
* Get the EventBase used by this socket.
* )
*
*/
- void setErrMessageCB(ErrMessageCallback* callback);
+ virtual void setErrMessageCB(ErrMessageCallback* callback);
/**
* Get a pointer to ErrMessageCallback implementation currently
* registered with this socket.
*
*/
- ErrMessageCallback* getErrMessageCallback() const;
+ virtual ErrMessageCallback* getErrMessageCallback() const;
/**
* Set a pointer to SendMsgParamsCallback implementation which
* will be used to form ::sendmsg() system call parameters
*
*/
- void setSendMsgParamCB(SendMsgParamsCallback* callback);
+ virtual void setSendMsgParamCB(SendMsgParamsCallback* callback);
/**
* Get a pointer to SendMsgParamsCallback implementation currently
* registered with this socket.
*
*/
- SendMsgParamsCallback* getSendMsgParamsCB() const;
+ virtual SendMsgParamsCallback* getSendMsgParamsCB() const;
// Read and write methods
void setReadCB(ReadCallback* callback) override;
void shutdownWriteNow() override;
bool readable() const override;
+ bool writable() const override;
bool isPending() const override;
virtual bool hangup() const;
bool good() const override;
return setsockopt(fd_, level, optname, optval, sizeof(T));
}
+ /**
+ * Virtual method for reading a socket option returning integer
+ * value, which is the most typical case. Convenient for overriding
+ * and mocking.
+ *
+ * @param level same as the "level" parameter in getsockopt().
+ * @param optname same as the "optname" parameter in getsockopt().
+ * @param optval same as "optval" parameter in getsockopt().
+ * @param optlen same as "optlen" parameter in getsockopt().
+ * @return same as the return value of getsockopt().
+ */
+ virtual int
+ getSockOptVirtual(int level, int optname, void* optval, socklen_t* optlen) {
+ return getsockopt(fd_, level, optname, optval, optlen);
+ }
+
+ /**
+ * Virtual method for setting a socket option accepting integer
+ * value, which is the most typical case. Convenient for overriding
+ * and mocking.
+ *
+ * @param level same as the "level" parameter in setsockopt().
+ * @param optname same as the "optname" parameter in setsockopt().
+ * @param optval same as "optval" parameter in setsockopt().
+ * @param optlen same as "optlen" parameter in setsockopt().
+ * @return same as the return value of setsockopt().
+ */
+ virtual int setSockOptVirtual(
+ int level,
+ int optname,
+ void const* optval,
+ socklen_t optlen) {
+ return setsockopt(fd_, level, optname, optval, optlen);
+ }
+
/**
* Set pre-received data, to be returned to read callback before any data
* from the socket.
noTransparentTls_ = true;
}
+ void disableTSocks() {
+ noTSocks_ = true;
+ }
+
enum class StateEnum : uint8_t {
UNINIT,
CONNECTING,
evbChangeCb_ = std::move(cb);
}
+ /**
+ * Attempt to cache the current local and peer addresses (if not already
+ * cached) so that they are available from getPeerAddress() and
+ * getLocalAddress() even after the socket is closed.
+ */
+ void cacheAddresses();
+
/**
* writeReturn is the total number of bytes written, or WRITE_ERROR on error.
* If no data has been written, 0 is returned.
* destroy() instead. (See the documentation in DelayedDestruction.h for
* more details.)
*/
- ~AsyncSocket();
+ ~AsyncSocket() override;
friend std::ostream& operator << (std::ostream& os, const StateEnum& state);
: AsyncTimeout(eventBase)
, socket_(socket) {}
- virtual void timeoutExpired() noexcept {
+ void timeoutExpired() noexcept override {
socket_->timeoutExpired();
}
: EventHandler(eventBase, fd)
, socket_(socket) {}
- virtual void handlerReady(uint16_t events) noexcept {
+ void handlerReady(uint16_t events) noexcept override {
socket_->ioReady(events);
}
std::string withAddr(const std::string& s);
+ void cacheLocalAddress() const;
+ void cachePeerAddress() const;
+
StateEnum state_; ///< StateEnum describing current state
uint8_t shutdownFlags_; ///< Shutdown state (ShutdownFlags)
uint16_t eventFlags_; ///< EventBase::HandlerFlags settings
bool tfoAttempted_{false};
bool tfoFinished_{false};
bool noTransparentTls_{false};
+ bool noTSocks_{false};
// Whether to track EOR or not.
bool trackEor_{false};