+
+TEST(AsyncSocketTest, REUSEPORT) {
+ EventBase base;
+ auto serverSocket = AsyncServerSocket::newSocket(&base);
+ serverSocket->bind(0);
+ serverSocket->listen(0);
+ serverSocket->startAccepting();
+
+ try {
+ serverSocket->setReusePortEnabled(true);
+ } catch(...) {
+ LOG(INFO) << "Reuse port probably not supported";
+ return;
+ }
+
+ SocketAddress address;
+ serverSocket->getAddress(&address);
+ int port = address.getPort();
+
+ auto serverSocket2 = AsyncServerSocket::newSocket(&base);
+ serverSocket2->setReusePortEnabled(true);
+ serverSocket2->bind(port);
+ serverSocket2->listen(0);
+ serverSocket2->startAccepting();
+
+}
+
+TEST(AsyncSocketTest, v4v6samePort) {
+ EventBase base;
+ auto serverSocket = AsyncServerSocket::newSocket(&base);
+ serverSocket->bind(0);
+ auto addrs = serverSocket->getAddresses();
+ ASSERT_GT(addrs.size(), 0);
+ uint16_t port = addrs[0].getPort();
+ for (const auto& addr : addrs) {
+ EXPECT_EQ(port, addr.getPort());
+ }
+}
+
+TEST(AsyncSocketTest, duplicateBind) {
+ EventBase base;
+ auto server1 = AsyncServerSocket::newSocket(&base);
+ server1->bind(0);
+ server1->listen(10);
+
+ SocketAddress address;
+ server1->getAddress(std::addressof(address));
+
+ auto server2 = AsyncServerSocket::newSocket(&base);
+ EXPECT_THROW(server2->bind(address.getPort()), std::exception);
+}
+
+} // namespace