Commit 53b24a32 authored by Yang Chi's avatar Yang Chi Committed by Facebook Github Bot

Make sendmsg in AsyncUDPSocket overridable

Summary: Add a protected virtual sendmsg method to AsyncUDPSocket. And make it default to call the system sendmsg function. This enables subclasses of AsyncUDPSocket to be able to override the behavior of sendmseg, also makes AsyncUDPSocket easier to mock and test.

Reviewed By: afrind

Differential Revision: D5459745

fbshipit-source-id: b0227bf7503b1096cb1f0bfc8b9c784db2f2e45d
parent e74ceef6
......@@ -176,7 +176,7 @@ ssize_t AsyncUDPSocket::writev(const folly::SocketAddress& address,
msg.msg_controllen = 0;
msg.msg_flags = 0;
return ::sendmsg(fd_, &msg, 0);
return sendmsg(fd_, &msg, 0);
}
void AsyncUDPSocket::resumeRead(ReadCallback* cob) {
......
......@@ -162,6 +162,11 @@ class AsyncUDPSocket : public EventHandler {
return eventBase_;
}
protected:
virtual ssize_t sendmsg(int socket, const struct msghdr* message, int flags) {
return ::sendmsg(socket, message, flags);
}
private:
AsyncUDPSocket(const AsyncUDPSocket&) = delete;
AsyncUDPSocket& operator=(const AsyncUDPSocket&) = delete;
......
......@@ -21,6 +21,7 @@
#include <folly/io/async/EventBase.h>
#include <folly/io/IOBuf.h>
#include <folly/portability/GMock.h>
#include <folly/portability/GTest.h>
#include <thread>
......@@ -31,6 +32,7 @@ using folly::AsyncTimeout;
using folly::EventBase;
using folly::SocketAddress;
using folly::IOBuf;
using namespace testing;
class UDPAcceptor
: public AsyncUDPServerSocket::Callback {
......@@ -289,3 +291,10 @@ TEST(AsyncSocketTest, PingPong) {
// Wait for server thread to joib
serverThread.join();
}
class TestAsyncUDPSocket : public AsyncUDPSocket {
public:
explicit TestAsyncUDPSocket(EventBase* evb) : AsyncUDPSocket(evb) {}
MOCK_METHOD3(sendmsg, ssize_t(int, const struct msghdr*, int));
};
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