本文整理汇总了C++中ListenSocket::getPort方法的典型用法代码示例。如果您正苦于以下问题:C++ ListenSocket::getPort方法的具体用法?C++ ListenSocket::getPort怎么用?C++ ListenSocket::getPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListenSocket
的用法示例。
在下文中一共展示了ListenSocket::getPort方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mcr
TEST(libmcrouter, listenSock) {
/* Create a listen socket, pass it to a child mcrouter and
check that communication through the socket works */
using namespace facebook::memcache;
ListenSocket listenSock;
std::vector<std::string> args{MCROUTER_INSTALL_PATH "mcrouter/mcrouter",
"--listen-sock-fd", folly::to<std::string>(listenSock.getSocketFd()),
"--config-str", configString };
auto testArgs = defaultTestCommandLineArgs();
args.insert(args.end(), testArgs.begin(), testArgs.end());
folly::Subprocess mcr(args);
SCOPE_EXIT {
mcr.terminate();
mcr.wait();
};
const std::string kSetRequest = "set testkey 0 0 1\r\nv\r\n";
const std::string kStoredReply = "STORED\r\n";
const std::string kGetRequest = "get testkey\r\n";
const std::string kGetReply = "VALUE testkey 0 1\r\nv\r\nEND\r\n";
ClientSocket mcrSock(listenSock.getPort());
EXPECT_EQ(kStoredReply, mcrSock.sendRequest(kSetRequest));
EXPECT_EQ(kGetReply, mcrSock.sendRequest(kGetRequest));
ClientSocket mcSock(memcacheLocal->getPort());
EXPECT_EQ(kGetReply, mcSock.sendRequest(kGetRequest));
}
示例2: umbrellaBinaryReply
void umbrellaBinaryReply(std::string data, mc_res_t expectedResult) {
ListenSocket sock;
std::thread serverThread([&sock, &data] {
auto sockFd = ::accept(sock.getSocketFd(), nullptr, nullptr);
// Don't read anything, just reply with a serialized reply.
size_t n = folly::writeFull(sockFd, data.data(), data.size());
CHECK(n == data.size());
});
TestClient client("localhost", sock.getPort(), 200, mc_umbrella_protocol);
client.sendGet("test", expectedResult);
client.waitForReplies();
serverThread.join();
}