Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 0 additions & 150 deletions folly/io/async/AsyncUDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,41 +268,6 @@ void AsyncUDPSocket::connect(const folly::SocketAddress& address) {
}
}

void AsyncUDPSocket::dontFragment(bool df) {
int optname4 = 0;
int optval4 = df ? 0 : 0;
int optname6 = 0;
int optval6 = df ? 0 : 0;
#if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO) && \
defined(IP_PMTUDISC_WANT)
optname4 = IP_MTU_DISCOVER;
optval4 = df ? IP_PMTUDISC_DO : IP_PMTUDISC_WANT;
#endif
#if defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO) && \
defined(IPV6_PMTUDISC_WANT)
optname6 = IPV6_MTU_DISCOVER;
optval6 = df ? IPV6_PMTUDISC_DO : IPV6_PMTUDISC_WANT;
#endif
if (optname4 && optval4 && address().getFamily() == AF_INET) {
if (netops::setsockopt(
fd_, IPPROTO_IP, optname4, &optval4, sizeof(optval4))) {
throw AsyncSocketException(
AsyncSocketException::NOT_OPEN,
"Failed to set DF with IP_MTU_DISCOVER",
errno);
}
}
if (optname6 && optval6 && address().getFamily() == AF_INET6) {
if (netops::setsockopt(
fd_, IPPROTO_IPV6, optname6, &optval6, sizeof(optval6))) {
throw AsyncSocketException(
AsyncSocketException::NOT_OPEN,
"Failed to set DF with IPV6_MTU_DISCOVER",
errno);
}
}
}

void AsyncUDPSocket::setDFAndTurnOffPMTU() {
int optname4 = 0;
int optval4 = 0;
Expand Down Expand Up @@ -370,48 +335,6 @@ void AsyncUDPSocket::setFD(NetworkSocket fd, FDOwnership ownership) {
localAddress_.setFromLocalAddress(fd_);
}

bool AsyncUDPSocket::setZeroCopy(bool enable) {
if (msgErrQueueSupported) {
zeroCopyVal_ = enable;

if (fd_ == NetworkSocket()) {
return false;
}

int val = enable ? 1 : 0;
int ret =
netops::setsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val));

// if enable == false, set zeroCopyEnabled_ = false regardless
// if SO_ZEROCOPY is set or not
if (!enable) {
zeroCopyEnabled_ = enable;
return true;
}

/* if the setsockopt failed, try to see if the socket inherited the flag
* since we cannot set SO_ZEROCOPY on a socket s = accept
*/
if (ret) {
val = 0;
socklen_t optlen = sizeof(val);
ret = netops::getsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &val, &optlen);

if (!ret) {
enable = val != 0;
}
}

if (!ret) {
zeroCopyEnabled_ = enable;

return true;
}
}

return false;
}

ssize_t AsyncUDPSocket::writeGSO(
const folly::SocketAddress& address,
const std::unique_ptr<folly::IOBuf>& buf,
Expand Down Expand Up @@ -1267,79 +1190,6 @@ int AsyncUDPSocket::getGRO() {
return gro_.value();
}

AsyncUDPSocket::TXTime AsyncUDPSocket::getTXTime() {
// check if we can return the cached value
if (FOLLY_UNLIKELY(!txTime_.has_value())) {
TXTime txTime;
#ifdef FOLLY_HAVE_MSG_ERRQUEUE
folly::netops::sock_txtime val = {};
socklen_t optlen = sizeof(val);
if (!netops::getsockopt(fd_, SOL_SOCKET, SO_TXTIME, &val, &optlen)) {
txTime.clockid = val.clockid;
txTime.deadline = (val.flags & folly::netops::SOF_TXTIME_DEADLINE_MODE);
}
#endif
txTime_ = txTime;
}

return txTime_.value();
}

bool AsyncUDPSocket::setTXTime(TXTime txTime) {
#ifdef FOLLY_HAVE_MSG_ERRQUEUE
folly::netops::sock_txtime val;
val.clockid = txTime.clockid;
val.flags = txTime.deadline ? folly::netops::SOF_TXTIME_DEADLINE_MODE : 0;
int ret =
netops::setsockopt(fd_, SOL_SOCKET, SO_TIMESTAMPING, &val, sizeof(val));

txTime_ = ret ? TXTime() : txTime;

return !ret;
#else
(void)txTime;
return false;
#endif
}

bool AsyncUDPSocket::setRxZeroChksum6(FOLLY_MAYBE_UNUSED bool bVal) {
#ifdef FOLLY_HAVE_MSG_ERRQUEUE
if (address().getFamily() != AF_INET6) {
return false;
}

int val = bVal ? 1 : 0;
int ret =
netops::setsockopt(fd_, SOL_UDP, UDP_NO_CHECK6_RX, &val, sizeof(val));
return !ret;
#else
return false;
#endif
}

bool AsyncUDPSocket::setTxZeroChksum6(FOLLY_MAYBE_UNUSED bool bVal) {
#ifdef FOLLY_HAVE_MSG_ERRQUEUE
if (address().getFamily() != AF_INET6) {
return false;
}

int val = bVal ? 1 : 0;
int ret =
netops::setsockopt(fd_, SOL_UDP, UDP_NO_CHECK6_TX, &val, sizeof(val));
return !ret;
#else
return false;
#endif
}

void AsyncUDPSocket::setTrafficClass(int tclass) {
if (netops::setsockopt(
fd_, IPPROTO_IPV6, IPV6_TCLASS, &tclass, sizeof(int)) != 0) {
throw AsyncSocketException(
AsyncSocketException::NOT_OPEN, "Failed to set IPV6_TCLASS", errno);
}
}

void AsyncUDPSocket::applyOptions(
const SocketOptionMap& options, SocketOptionKey::ApplyPos pos) {
auto result = applySocketOptions(fd_, options, pos);
Expand Down
69 changes: 1 addition & 68 deletions folly/io/async/AsyncUDPSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,6 @@ class AsyncUDPSocket : public EventHandler {
*/
virtual void setFD(NetworkSocket fd, FDOwnership ownership);

bool setZeroCopy(bool enable);
bool getZeroCopy() const { return zeroCopyEnabled_; }

uint32_t getZeroCopyBufId() const { return zeroCopyBufId_; }

size_t getZeroCopyReenableThreshold() const {
return zeroCopyReenableThreshold_;
}

void setZeroCopyReenableThreshold(size_t threshold) {
zeroCopyReenableThreshold_ = threshold;
}

/**
* Set extra control messages to send
*/
Expand Down Expand Up @@ -374,7 +361,7 @@ class AsyncUDPSocket : public EventHandler {
* its own PMTU Discovery mechanism.
* Note this doesn't work on Apple.
*/
virtual void dontFragment(bool df);
// virtual void dontFragment(bool df);

/**
* Set Dont-Fragment (DF) but ignore Path MTU.
Expand All @@ -395,26 +382,6 @@ class AsyncUDPSocket : public EventHandler {

virtual bool isReading() const { return readCallback_ != nullptr; }

/**
* Set the maximum number of reads to execute from the underlying
* socket each time the EventBase detects that new ingress data is
* available. The default is kMaxReadsPerEvent
*
* @param maxReads Maximum number of reads per data-available event;
* a value of zero means unlimited.
*/
void setMaxReadsPerEvent(uint16_t maxReads) { maxReadsPerEvent_ = maxReads; }

/**
* Get the maximum number of reads this object will execute from
* the underlying socket each time the EventBase detects that new
* ingress data is available.
*
* @returns Maximum number of reads per data-available event; a value
* of zero means unlimited.
*/
uint16_t getMaxReadsPerEvent() const { return maxReadsPerEvent_; }

virtual void detachEventBase();

virtual void attachEventBase(folly::EventBase* evb);
Expand All @@ -425,10 +392,6 @@ class AsyncUDPSocket : public EventHandler {

bool setGSO(int val);

void setIOBufFreeFunc(IOBufFreeFunc&& ioBufFreeFunc) {
ioBufFreeFunc_ = std::move(ioBufFreeFunc);
}

// generic receive offload get/set
// negative return value means GRO is not available
int getGRO();
Expand All @@ -444,39 +407,9 @@ class AsyncUDPSocket : public EventHandler {
int getTimestamping();
bool setTimestamping(int val);

// disable/enable RX zero checksum check for UDP over IPv6
bool setRxZeroChksum6(bool bVal);

// disable/enable TX zero checksum for UDP over IPv6
bool setTxZeroChksum6(bool bVal);

void setTrafficClass(int tclass);

void applyOptions(
const SocketOptionMap& options, SocketOptionKey::ApplyPos pos);

/**
* Override netops::Dispatcher to be used for netops:: calls.
*
* Pass empty shared_ptr to reset to default.
* Override can be used by unit tests to intercept and mock netops:: calls.
*/
virtual void setOverrideNetOpsDispatcher(
std::shared_ptr<netops::Dispatcher> dispatcher) {
netops_.setOverride(std::move(dispatcher));
}

/**
* Returns override netops::Dispatcher being used for netops:: calls.
*
* Returns empty shared_ptr if no override set.
* Override can be used by unit tests to intercept and mock netops:: calls.
*/
virtual std::shared_ptr<netops::Dispatcher> getOverrideNetOpsDispatcher()
const {
return netops_.getOverride();
}

protected:
struct full_sockaddr_storage {
sockaddr_storage storage;
Expand Down