mirror of
https://github.com/oatpp/oatpp.git
synced 2025-01-18 16:43:57 +08:00
server::SimpleTCPConnectionProvider use select-accept.
This commit is contained in:
parent
a765253ed5
commit
292647ca93
@ -182,7 +182,7 @@ oatpp::data::v_io_handle SimpleTCPConnectionProvider::instantiateServer(){
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
fcntl(serverHandle, F_SETFL, 0);//O_NONBLOCK);
|
||||
fcntl(serverHandle, F_SETFL, O_NONBLOCK);
|
||||
|
||||
return serverHandle;
|
||||
|
||||
@ -278,11 +278,30 @@ std::shared_ptr<oatpp::data::stream::IOStream> SimpleTCPConnectionProvider::getE
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<oatpp::data::stream::IOStream> SimpleTCPConnectionProvider::getConnection(){
|
||||
std::shared_ptr<oatpp::data::stream::IOStream> SimpleTCPConnectionProvider::getConnection() {
|
||||
|
||||
fd_set set;
|
||||
struct timeval timeout;
|
||||
int rv;
|
||||
FD_ZERO(&set);
|
||||
FD_SET(m_serverHandle, &set);
|
||||
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
while(!m_closed) {
|
||||
auto res = select(m_serverHandle + 1, &set, nullptr, nullptr, &timeout);
|
||||
if (res >= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_useExtendedConnections) {
|
||||
return getExtendedConnection();
|
||||
}
|
||||
|
||||
return getDefaultConnection();
|
||||
|
||||
}
|
||||
|
||||
}}}
|
||||
|
@ -123,7 +123,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
void runServer(v_int32 port, v_int32 delaySeconds, v_int32 iterations, bool stable, const std::shared_ptr<app::Controller>& controller, bool wakeupServer) {
|
||||
void runServer(v_int32 port, v_int32 delaySeconds, v_int32 iterations, bool stable, const std::shared_ptr<app::Controller>& controller) {
|
||||
|
||||
TestServerComponent component(port);
|
||||
|
||||
@ -131,7 +131,7 @@ void runServer(v_int32 port, v_int32 delaySeconds, v_int32 iterations, bool stab
|
||||
|
||||
runner.addController(controller);
|
||||
|
||||
runner.run([&runner, delaySeconds, iterations, stable, controller, wakeupServer] {
|
||||
runner.run([&runner, delaySeconds, iterations, stable, controller] {
|
||||
|
||||
for(v_int32 i = 0; i < iterations; i ++) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(delaySeconds));
|
||||
@ -141,15 +141,6 @@ void runServer(v_int32 port, v_int32 delaySeconds, v_int32 iterations, bool stab
|
||||
}
|
||||
}
|
||||
|
||||
if(wakeupServer) {
|
||||
|
||||
runner.getServer()->stop();
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider);
|
||||
connectionProvider->getConnection();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, std::chrono::minutes(10));
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
@ -226,7 +217,7 @@ void ClientRetryTest::onRun() {
|
||||
OATPP_LOGD(TAG, "Waiting for server to start...");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
|
||||
runServer(m_port, 1, 1, true, controller, true);
|
||||
runServer(m_port, 1, 1, true, controller);
|
||||
|
||||
for(std::thread& thread : threads) {
|
||||
thread.join();
|
||||
@ -271,7 +262,7 @@ void ClientRetryTest::onRun() {
|
||||
|
||||
});
|
||||
|
||||
runServer(m_port, 2, 6, false, controller, true);
|
||||
runServer(m_port, 2, 6, false, controller);
|
||||
|
||||
clientThread.join();
|
||||
|
||||
|
@ -317,15 +317,6 @@ void FullAsyncClientTest::onRun() {
|
||||
|
||||
executor->waitTasksFinished(); // Wait executor tasks before quit.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Stop server and unblock accepting thread
|
||||
|
||||
runner.getServer()->stop();
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider);
|
||||
connectionProvider->getConnection();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}, std::chrono::minutes(10));
|
||||
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::async::Executor>, executor);
|
||||
|
@ -274,16 +274,7 @@ void FullAsyncTest::onRun() {
|
||||
}
|
||||
|
||||
connection.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Stop server and unblock accepting thread
|
||||
|
||||
runner.getServer()->stop();
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider);
|
||||
connectionProvider->getConnection();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
|
||||
}, std::chrono::minutes(10));
|
||||
|
||||
|
@ -448,15 +448,6 @@ void FullTest::onRun() {
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Stop server and unblock accepting thread
|
||||
|
||||
runner.getServer()->stop();
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider);
|
||||
connectionProvider->getConnection();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}, std::chrono::minutes(10));
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
@ -179,20 +179,10 @@ void PipelineAsyncTest::onRun() {
|
||||
// Stop server and unblock accepting thread
|
||||
|
||||
connection.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Stop server and unblock accepting thread
|
||||
|
||||
runner.getServer()->stop();
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider);
|
||||
connectionProvider->getConnection();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
|
||||
}, std::chrono::minutes(10));
|
||||
|
||||
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::async::Executor>, executor);
|
||||
executor->waitTasksFinished();
|
||||
executor->join();
|
||||
|
@ -173,15 +173,6 @@ void PipelineTest::onRun() {
|
||||
pipeOutThread.join();
|
||||
pipeInThread.join();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Stop server and unblock accepting thread
|
||||
|
||||
runner.getServer()->stop();
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, connectionProvider);
|
||||
connectionProvider->getConnection();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}, std::chrono::minutes(10));
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
Loading…
Reference in New Issue
Block a user