22 #include <glog/logging.h> 40 void stop(
bool abortive);
62 addr.sin_family = AF_INET;
64 addr.sin_addr.s_addr = INADDR_ANY;
66 acceptSocket_, reinterpret_cast<const sockaddr*>(&addr),
sizeof(addr)));
70 socklen_t addrLen =
sizeof(
addr);
74 port_ = ntohs(addr.sin_port);
79 socklen_t peerLen =
sizeof(peer);
86 if (errno == EINVAL || errno == ENOTSOCK) {
91 shutdownSocketSet.
add(fd);
106 for (
int fd :
fds_) {
108 struct linger l = {1, 0};
109 CHECK_ERR(
setsockopt(fd, SOL_SOCKET, SO_LINGER, &l,
sizeof(l)));
111 shutdownSocketSet.
close(fd);
131 addr.sin_family = AF_INET;
132 addr.sin_port = htons(port);
133 addr.sin_addr.s_addr = htonl((127 << 24) | 1);
135 connect(sock, reinterpret_cast<const sockaddr*>(&addr),
sizeof(addr)));
144 std::thread stopper([&server, abortive] {
145 std::this_thread::sleep_for(std::chrono::milliseconds(200));
146 server.
stop(abortive);
151 int r =
read(sock, &c, 1);
167 TEST(ShutdownSocketSetTest, OrderlyClose) {
171 TEST(ShutdownSocketSetTest, AbortiveClose) {
180 std::thread killer([&server, abortive] {
181 std::this_thread::sleep_for(std::chrono::milliseconds(200));
187 int r =
read(sock, &c, 1);
209 TEST(ShutdownSocketSetTest, OrderlyKill) {
213 TEST(ShutdownSocketSetTest, AbortiveKill) {
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
int setsockopt(NetworkSocket s, int level, int optname, const void *optval, socklen_t optlen)
#define EXPECT_EQ(val1, val2)
std::atomic< StopMode > stop_
int createConnectedSocket(int port)
—— Concurrent Priority Queue Implementation ——
int closeClients(bool abortive)
void runKillTest(bool abortive)
int getsockname(NetworkSocket s, sockaddr *name, socklen_t *namelen)
size_t read(T &out, folly::io::Cursor &cursor)
ShutdownSocketSet shutdownSocketSet
NetworkSocket socket(int af, int type, int protocol)
int listen(NetworkSocket s, int backlog)
std::thread serverThread_
TEST(ProgramOptionsTest, Errors)
void shutdownAll(bool abortive=false)
int bind(NetworkSocket s, const sockaddr *name, socklen_t namelen)
int close(NetworkSocket s)
ThreadPoolListHook * addr
void runCloseTest(bool abortive)
NetworkSocket accept(NetworkSocket s, sockaddr *addr, socklen_t *addrlen)