Commit ee1e6c7b authored by Matt Joras's avatar Matt Joras Committed by Facebook GitHub Bot

Add recvmmsg weak symbol.

Summary:
As it turns out, to use this reliably on Android we need to define a weak symbol. The headers are only exported after API level 21, so apps that compile with 16 cannot use it with a compile time flag.

Instead we can utilize a weak symbol to link with it, and check if it's there at runtime.

Reviewed By: yfeldblum

Differential Revision: D21535034

fbshipit-source-id: 8b68a803d1e9f2f293e9f3efa16fb2a18abee53d
parent a3e63b14
......@@ -32,6 +32,24 @@
#include <folly/ScopeGuard.h>
#endif
#if !FOLLY_HAVE_RECVMMSG
#if FOLLY_HAVE_WEAK_SYMBOLS
extern "C" FOLLY_ATTR_WEAK int recvmmsg(
int sockfd,
struct mmsghdr* msgvec,
unsigned int vlen,
unsigned int flags,
struct timespec* timeout);
#else
static int (*recvmmsg)(
int sockfd,
struct mmsghdr* msgvec,
unsigned int vlen,
unsigned int flags,
struct timespec* timeout) = nullptr;
#endif // FOLLY_HAVE_WEAK_SYMBOLS
#endif // FOLLY_HAVE_RECVMMSG
namespace folly {
namespace netops {
......@@ -322,9 +340,9 @@ int recvmmsg(
unsigned int vlen,
unsigned int flags,
timespec* timeout) {
#if FOLLY_HAVE_RECVMMSG
return wrapSocketFunction<int>(::recvmmsg, s, msgvec, vlen, flags, timeout);
#else
if (reinterpret_cast<void*>(::recvmmsg) != nullptr) {
return wrapSocketFunction<int>(::recvmmsg, s, msgvec, vlen, flags, timeout);
}
// implement via recvmsg
for (unsigned int i = 0; i < vlen; i++) {
ssize_t ret = recvmsg(s, &msgvec[i].msg_hdr, flags);
......@@ -341,7 +359,6 @@ int recvmmsg(
}
}
return static_cast<int>(vlen);
#endif
}
ssize_t send(NetworkSocket s, const void* buf, size_t len, int flags) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment