/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2014-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <iostream>
-#include <folly/io/async/AsyncSocket.h>
#include <folly/io/async/AsyncServerSocket.h>
+#include <folly/io/async/AsyncSocket.h>
#include <folly/io/async/EventBase.h>
-
-#include <gtest/gtest.h>
+#include <folly/portability/GTest.h>
namespace folly {
}
}
-} // namespace
+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 folly