Commit 7657c306 authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Port AsyncSocketTest2 to NetworkSocket

Summary:
Shift the tests as well.

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D12981653

fbshipit-source-id: 0fda732df3882218746c173c885bff06b86abbac
parent b31ebff2
This diff is collapsed.
...@@ -143,15 +143,14 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback { ...@@ -143,15 +143,14 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback {
public: public:
enum EventType { TYPE_START, TYPE_ACCEPT, TYPE_ERROR, TYPE_STOP }; enum EventType { TYPE_START, TYPE_ACCEPT, TYPE_ERROR, TYPE_STOP };
struct EventInfo { struct EventInfo {
EventInfo(int fd_, const folly::SocketAddress& addr) EventInfo(folly::NetworkSocket fd_, const folly::SocketAddress& addr)
: type(TYPE_ACCEPT), fd(fd_), address(addr), errorMsg() {} : type(TYPE_ACCEPT), fd(fd_), address(addr), errorMsg() {}
explicit EventInfo(const std::string& msg) explicit EventInfo(const std::string& msg)
: type(TYPE_ERROR), fd(-1), address(), errorMsg(msg) {} : type(TYPE_ERROR), fd(), address(), errorMsg(msg) {}
explicit EventInfo(EventType et) explicit EventInfo(EventType et) : type(et), fd(), address(), errorMsg() {}
: type(et), fd(-1), address(), errorMsg() {}
EventType type; EventType type;
int fd; // valid for TYPE_ACCEPT folly::NetworkSocket fd; // valid for TYPE_ACCEPT
folly::SocketAddress address; // valid for TYPE_ACCEPT folly::SocketAddress address; // valid for TYPE_ACCEPT
std::string errorMsg; // valid for TYPE_ERROR std::string errorMsg; // valid for TYPE_ERROR
}; };
...@@ -168,7 +167,8 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback { ...@@ -168,7 +167,8 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback {
} }
void setConnectionAcceptedFn( void setConnectionAcceptedFn(
const std::function<void(int, const folly::SocketAddress&)>& fn) { const std::function<void(NetworkSocket, const folly::SocketAddress&)>&
fn) {
connectionAcceptedFn_ = fn; connectionAcceptedFn_ = fn;
} }
void setAcceptErrorFn(const std::function<void(const std::exception&)>& fn) { void setAcceptErrorFn(const std::function<void(const std::exception&)>& fn) {
...@@ -184,10 +184,10 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback { ...@@ -184,10 +184,10 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback {
void connectionAccepted( void connectionAccepted(
int fd, int fd,
const folly::SocketAddress& clientAddr) noexcept override { const folly::SocketAddress& clientAddr) noexcept override {
events_.emplace_back(fd, clientAddr); events_.emplace_back(NetworkSocket::fromFd(fd), clientAddr);
if (connectionAcceptedFn_) { if (connectionAcceptedFn_) {
connectionAcceptedFn_(fd, clientAddr); connectionAcceptedFn_(NetworkSocket::fromFd(fd), clientAddr);
} }
} }
void acceptError(const std::exception& ex) noexcept override { void acceptError(const std::exception& ex) noexcept override {
...@@ -213,7 +213,8 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback { ...@@ -213,7 +213,8 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback {
} }
private: private:
std::function<void(int, const folly::SocketAddress&)> connectionAcceptedFn_; std::function<void(NetworkSocket, const folly::SocketAddress&)>
connectionAcceptedFn_;
std::function<void(const std::exception&)> acceptErrorFn_; std::function<void(const std::exception&)> acceptErrorFn_;
std::function<void()> acceptStartedFn_; std::function<void()> acceptStartedFn_;
std::function<void()> acceptStoppedFn_; std::function<void()> acceptStoppedFn_;
......
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