Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
zeshuai007 | 6b1cb30 | 2020-05-27 12:08:01 +0800 | [diff] [blame^] | 20 | #include <boost/test/unit_test.hpp> |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 21 | #include <boost/test/unit_test_suite.hpp> |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 22 | #include <boost/chrono/duration.hpp> |
| 23 | #include <boost/date_time/posix_time/posix_time_duration.hpp> |
| 24 | #include <boost/thread/thread.hpp> |
| 25 | #include <boost/filesystem.hpp> |
| 26 | #include <boost/format.hpp> |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 27 | #include <memory> |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 28 | #include <thrift/transport/TSSLSocket.h> |
| 29 | #include <thrift/transport/TSSLServerSocket.h> |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 30 | #ifdef __linux__ |
| 31 | #include <signal.h> |
| 32 | #endif |
| 33 | |
| 34 | using apache::thrift::transport::TSSLServerSocket; |
| 35 | using apache::thrift::transport::TSSLSocket; |
| 36 | using apache::thrift::transport::TTransport; |
| 37 | using apache::thrift::transport::TTransportException; |
| 38 | using apache::thrift::transport::TSSLSocketFactory; |
| 39 | |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 40 | using std::static_pointer_cast; |
| 41 | using std::shared_ptr; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 42 | |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 43 | BOOST_AUTO_TEST_SUITE(TSSLSocketInterruptTest) |
| 44 | |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 45 | boost::filesystem::path keyDir; |
| 46 | boost::filesystem::path certFile(const std::string& filename) |
| 47 | { |
| 48 | return keyDir / filename; |
| 49 | } |
| 50 | boost::mutex gMutex; |
| 51 | |
| 52 | struct GlobalFixtureSSL |
| 53 | { |
| 54 | GlobalFixtureSSL() |
| 55 | { |
| 56 | using namespace boost::unit_test::framework; |
| 57 | for (int i = 0; i < master_test_suite().argc; ++i) |
| 58 | { |
| 59 | BOOST_TEST_MESSAGE(boost::format("argv[%1%] = \"%2%\"") % i % master_test_suite().argv[i]); |
| 60 | } |
| 61 | |
| 62 | #ifdef __linux__ |
| 63 | // OpenSSL calls send() without MSG_NOSIGPIPE so writing to a socket that has |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 64 | // disconnected can cause a SIGPIPE signal... |
| 65 | signal(SIGPIPE, SIG_IGN); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 66 | #endif |
| 67 | |
| 68 | TSSLSocketFactory::setManualOpenSSLInitialization(true); |
| 69 | apache::thrift::transport::initializeOpenSSL(); |
| 70 | |
| 71 | keyDir = boost::filesystem::current_path().parent_path().parent_path().parent_path() / "test" / "keys"; |
| 72 | if (!boost::filesystem::exists(certFile("server.crt"))) |
| 73 | { |
| 74 | keyDir = boost::filesystem::path(master_test_suite().argv[master_test_suite().argc - 1]); |
| 75 | if (!boost::filesystem::exists(certFile("server.crt"))) |
| 76 | { |
| 77 | throw std::invalid_argument("The last argument to this test must be the directory containing the test certificate(s)."); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | virtual ~GlobalFixtureSSL() |
| 83 | { |
| 84 | apache::thrift::transport::cleanupOpenSSL(); |
| 85 | #ifdef __linux__ |
| 86 | signal(SIGPIPE, SIG_DFL); |
| 87 | #endif |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | #if (BOOST_VERSION >= 105900) |
| 92 | BOOST_GLOBAL_FIXTURE(GlobalFixtureSSL); |
| 93 | #else |
| 94 | BOOST_GLOBAL_FIXTURE(GlobalFixtureSSL) |
| 95 | #endif |
| 96 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 97 | void readerWorker(shared_ptr<TTransport> tt, uint32_t expectedResult) { |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 98 | uint8_t buf[4]; |
| 99 | try { |
| 100 | tt->read(buf, 1); |
| 101 | BOOST_CHECK_EQUAL(expectedResult, tt->read(buf, 4)); |
| 102 | } catch (const TTransportException& tx) { |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 103 | BOOST_CHECK_EQUAL(TTransportException::TIMED_OUT, tx.getType()); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 107 | void readerWorkerMustThrow(shared_ptr<TTransport> tt) { |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 108 | try { |
| 109 | uint8_t buf[400]; |
| 110 | tt->read(buf, 1); |
| 111 | tt->read(buf, 400); |
| 112 | BOOST_ERROR("should not have gotten here"); |
| 113 | } catch (const TTransportException& tx) { |
| 114 | BOOST_CHECK_EQUAL(TTransportException::INTERRUPTED, tx.getType()); |
| 115 | } |
| 116 | } |
| 117 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 118 | shared_ptr<TSSLSocketFactory> createServerSocketFactory() { |
| 119 | shared_ptr<TSSLSocketFactory> pServerSocketFactory; |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 120 | |
| 121 | pServerSocketFactory.reset(new TSSLSocketFactory()); |
| 122 | pServerSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 123 | pServerSocketFactory->loadCertificate(certFile("server.crt").string().c_str()); |
| 124 | pServerSocketFactory->loadPrivateKey(certFile("server.key").string().c_str()); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 125 | pServerSocketFactory->server(true); |
| 126 | return pServerSocketFactory; |
| 127 | } |
| 128 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 129 | shared_ptr<TSSLSocketFactory> createClientSocketFactory() { |
| 130 | shared_ptr<TSSLSocketFactory> pClientSocketFactory; |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 131 | |
| 132 | pClientSocketFactory.reset(new TSSLSocketFactory()); |
| 133 | pClientSocketFactory->authenticate(true); |
Antonio Di Monaco | 796667b | 2016-01-04 23:05:19 +0100 | [diff] [blame] | 134 | pClientSocketFactory->loadCertificate(certFile("client.crt").string().c_str()); |
| 135 | pClientSocketFactory->loadPrivateKey(certFile("client.key").string().c_str()); |
| 136 | pClientSocketFactory->loadTrustedCertificates(certFile("CA.pem").string().c_str()); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 137 | return pClientSocketFactory; |
| 138 | } |
| 139 | |
| 140 | BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read_while_handshaking) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 141 | shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 142 | TSSLServerSocket sock1("localhost", 0, pServerSocketFactory); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 143 | sock1.listen(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 144 | int port = sock1.getPort(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 145 | shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory(); |
| 146 | shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 147 | clientSock->open(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 148 | shared_ptr<TTransport> accepted = sock1.accept(); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 149 | boost::thread readThread(std::bind(readerWorkerMustThrow, accepted)); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 150 | boost::this_thread::sleep(boost::posix_time::milliseconds(50)); |
| 151 | // readThread is practically guaranteed to be blocking now |
| 152 | sock1.interruptChildren(); |
| 153 | BOOST_CHECK_MESSAGE(readThread.try_join_for(boost::chrono::milliseconds(20)), |
| 154 | "server socket interruptChildren did not interrupt child read"); |
| 155 | clientSock->close(); |
| 156 | accepted->close(); |
| 157 | sock1.close(); |
| 158 | } |
| 159 | |
| 160 | BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 161 | shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 162 | TSSLServerSocket sock1("localhost", 0, pServerSocketFactory); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 163 | sock1.listen(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 164 | int port = sock1.getPort(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 165 | shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory(); |
| 166 | shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 167 | clientSock->open(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 168 | shared_ptr<TTransport> accepted = sock1.accept(); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 169 | boost::thread readThread(std::bind(readerWorkerMustThrow, accepted)); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 170 | clientSock->write((const uint8_t*)"0", 1); |
| 171 | boost::this_thread::sleep(boost::posix_time::milliseconds(50)); |
| 172 | // readThread is practically guaranteed to be blocking now |
| 173 | sock1.interruptChildren(); |
| 174 | BOOST_CHECK_MESSAGE(readThread.try_join_for(boost::chrono::milliseconds(20)), |
| 175 | "server socket interruptChildren did not interrupt child read"); |
| 176 | accepted->close(); |
| 177 | clientSock->close(); |
| 178 | sock1.close(); |
| 179 | } |
| 180 | |
| 181 | BOOST_AUTO_TEST_CASE(test_ssl_non_interruptable_child_read) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 182 | shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 183 | TSSLServerSocket sock1("localhost", 0, pServerSocketFactory); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 184 | sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior |
| 185 | sock1.listen(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 186 | int port = sock1.getPort(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 187 | shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory(); |
| 188 | shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 189 | clientSock->open(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 190 | shared_ptr<TTransport> accepted = sock1.accept(); |
| 191 | static_pointer_cast<TSSLSocket>(accepted)->setRecvTimeout(1000); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 192 | boost::thread readThread(std::bind(readerWorker, accepted, 0)); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 193 | clientSock->write((const uint8_t*)"0", 1); |
| 194 | boost::this_thread::sleep(boost::posix_time::milliseconds(50)); |
| 195 | // readThread is practically guaranteed to be blocking here |
| 196 | sock1.interruptChildren(); |
| 197 | BOOST_CHECK_MESSAGE(!readThread.try_join_for(boost::chrono::milliseconds(200)), |
| 198 | "server socket interruptChildren interrupted child read"); |
| 199 | |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 200 | // wait for receive timeout to kick in |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 201 | readThread.join(); |
| 202 | accepted->close(); |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 203 | clientSock->close(); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 204 | sock1.close(); |
| 205 | } |
| 206 | |
| 207 | BOOST_AUTO_TEST_CASE(test_ssl_cannot_change_after_listen) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 208 | shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 209 | TSSLServerSocket sock1("localhost", 0, pServerSocketFactory); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 210 | sock1.listen(); |
| 211 | BOOST_CHECK_THROW(sock1.setInterruptableChildren(false), std::logic_error); |
| 212 | sock1.close(); |
| 213 | } |
| 214 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 215 | void peekerWorker(shared_ptr<TTransport> tt, bool expectedResult) { |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 216 | uint8_t buf[400]; |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 217 | try { |
| 218 | tt->read(buf, 1); |
James E. King, III | 07f5997 | 2017-03-10 06:18:33 -0500 | [diff] [blame] | 219 | BOOST_CHECK_EQUAL(expectedResult, tt->peek()); |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 220 | } catch (const TTransportException& tx) { |
| 221 | BOOST_CHECK_EQUAL(TTransportException::TIMED_OUT, tx.getType()); |
| 222 | } |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 223 | } |
| 224 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 225 | void peekerWorkerInterrupt(shared_ptr<TTransport> tt) { |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 226 | uint8_t buf[400]; |
| 227 | try { |
| 228 | tt->read(buf, 1); |
| 229 | tt->peek(); |
| 230 | } catch (const TTransportException& tx) { |
| 231 | BOOST_CHECK_EQUAL(TTransportException::INTERRUPTED, tx.getType()); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_peek) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 236 | shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 237 | TSSLServerSocket sock1("localhost", 0, pServerSocketFactory); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 238 | sock1.listen(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 239 | int port = sock1.getPort(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 240 | shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory(); |
| 241 | shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 242 | clientSock->open(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 243 | shared_ptr<TTransport> accepted = sock1.accept(); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 244 | boost::thread peekThread(std::bind(peekerWorkerInterrupt, accepted)); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 245 | clientSock->write((const uint8_t*)"0", 1); |
| 246 | boost::this_thread::sleep(boost::posix_time::milliseconds(50)); |
| 247 | // peekThread is practically guaranteed to be blocking now |
| 248 | sock1.interruptChildren(); |
| 249 | BOOST_CHECK_MESSAGE(peekThread.try_join_for(boost::chrono::milliseconds(200)), |
| 250 | "server socket interruptChildren did not interrupt child peek"); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 251 | accepted->close(); |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 252 | clientSock->close(); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 253 | sock1.close(); |
| 254 | } |
| 255 | |
| 256 | BOOST_AUTO_TEST_CASE(test_ssl_non_interruptable_child_peek) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 257 | shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 258 | TSSLServerSocket sock1("localhost", 0, pServerSocketFactory); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 259 | sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior |
| 260 | sock1.listen(); |
John Sirois | b867b27 | 2016-02-12 17:44:01 -0700 | [diff] [blame] | 261 | int port = sock1.getPort(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 262 | shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory(); |
| 263 | shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 264 | clientSock->open(); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 265 | shared_ptr<TTransport> accepted = sock1.accept(); |
| 266 | static_pointer_cast<TSSLSocket>(accepted)->setRecvTimeout(1000); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 267 | boost::thread peekThread(std::bind(peekerWorker, accepted, false)); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 268 | clientSock->write((const uint8_t*)"0", 1); |
| 269 | boost::this_thread::sleep(boost::posix_time::milliseconds(50)); |
| 270 | // peekThread is practically guaranteed to be blocking now |
| 271 | sock1.interruptChildren(); |
| 272 | BOOST_CHECK_MESSAGE(!peekThread.try_join_for(boost::chrono::milliseconds(200)), |
| 273 | "server socket interruptChildren interrupted child peek"); |
| 274 | |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 275 | // wait for the receive timeout to kick in |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 276 | peekThread.join(); |
| 277 | accepted->close(); |
tpcwang | af81cf0 | 2016-10-05 09:48:23 -0700 | [diff] [blame] | 278 | clientSock->close(); |
Martin Haimberger | 0ad6ee9 | 2015-11-13 03:18:50 -0800 | [diff] [blame] | 279 | sock1.close(); |
| 280 | } |
| 281 | |
| 282 | BOOST_AUTO_TEST_SUITE_END() |