From ff75e313831aa787a4b0b1167f6be07475b593b9 Mon Sep 17 00:00:00 2001 From: Harvey Fong Date: Sat, 1 Mar 2025 11:29:27 -0700 Subject: [PATCH] switched to connection_state only, server threads should never break loop, copy command bug fixed by switching to new form for vcxproj --- bellatui.cpp | 28 ++++++++++++---------------- bellatui.vcxproj | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/bellatui.cpp b/bellatui.cpp index a9ecaa0..ab27eaa 100644 --- a/bellatui.cpp +++ b/bellatui.cpp @@ -26,7 +26,7 @@ using namespace dl; using namespace dl::bella_sdk; -std::atomic heartbeat_state (true); +//std::atomic heartbeat_state (true); std::atomic connection_state (false); std::atomic abort_state (false); std::atomic server (false); @@ -104,7 +104,6 @@ void heartbeat_thread( std::string server_pkey, //CLIENT bool is_server, //BOTH std::string server_address, //CLIENT uint16_t heartbeat_port ) { //BOTH - heartbeat_state = true; zmq::context_t ctx; zmq::socket_t heartbeat_sock; //top scope @@ -121,7 +120,7 @@ void heartbeat_thread( std::string server_pkey, //CLIENT zmq::pollitem_t response_item = { heartbeat_sock, 0, ZMQ_POLLIN, 0 }; zmq::poll(&response_item, 1, 5000); // Wait for response with timeout - if (response_item.revents & ZMQ_POLLIN) { + if (response_item.revents & ZMQ_POLLIN) { //heartbeat zmq::message_t message; //ZIN<<< heartbeat_sock.recv(message, zmq::recv_flags::none); @@ -129,7 +128,7 @@ void heartbeat_thread( std::string server_pkey, //CLIENT heartbeat_sock.send(zmq::message_t("ACK"), zmq::send_flags::dontwait); // No block } else { //timeout std::cout << "Bella Client Lost" << std::endl; - heartbeat_state = false; + connection_state = false; } } std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -161,7 +160,6 @@ void heartbeat_thread( std::string server_pkey, //CLIENT //std::cout << "Heartbeat Response: " << std::endl; } else { std::cout << "Bella Server is unavailable" << std::endl; - heartbeat_state = false; connection_state = false; break; } @@ -285,25 +283,25 @@ int DL_main(Args& args) heartbeat_port); //bind port // while(true) { // awaiting new client loop - heartbeat_state = true; std::cout << "Awaiting new client ..." << std::endl; pkey_server(server_pkey, publickey_port); // blocking wait client to get public key std::cout << "Client connected" << std::endl; + connection_state = true; while(true) { // inner loop - if (heartbeat_state.load()==false) { + if (connection_state.load()==false) { std::cout << "Client connectiono dead" << std::endl; break; // Go back to awaiting client } std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } - abort_state==true; + //abort_state==true; server_t.join(); heartbeat_t.join(); return 0; - } else { + } else { //Client char client_skey[41] = { 0 }; char client_pkey[41] = { 0 }; if ( zmq_curve_keypair(&client_pkey[0], &client_skey[0])) { @@ -334,11 +332,11 @@ int DL_main(Args& args) heartbeat_port); //connect port while (true) { - if (!heartbeat_state.load()) { + /*if (!heartbeat_state.load()) { std::cout << "Dead" << std::endl; abort_state==true; break; - } + }*/ if (connection_state.load() == false) { std::cout << "Dead2" << std::endl; abort_state==true; @@ -612,6 +610,7 @@ void server_thread( std::string server_skey, std::ofstream binaryOutputFile;// for writing std::ifstream binaryInputFile;// for reading while (true) { + std::cout << "expect\n"; zmq::message_t msg_command; //ZIN<<< command_sock.recv(msg_command, zmq::recv_flags::none); @@ -626,10 +625,7 @@ void server_thread( std::string server_skey, std::cout << "Client disconnecting..." << std::endl; //>>>ZOUT command_sock.send(zmq::message_t("RDY"), zmq::send_flags::none); - heartbeat_state = false; - connection_state = false; - abort_state = true; - break; + connection_state = false; //<< // RENDER } else if (client_command == "render") { std::cout << "start render" << std::endl; @@ -837,4 +833,4 @@ void pkey_server(const std::string& pub_key, uint16_t publickey_port) { } sock.close(); ctx.close(); -} \ No newline at end of file +} diff --git a/bellatui.vcxproj b/bellatui.vcxproj index d9974c1..9fca9c6 100644 --- a/bellatui.vcxproj +++ b/bellatui.vcxproj @@ -91,7 +91,19 @@ - copy "$(ProjectDir)..\bella_engine_sdk\lib\*.dll" "$(TargetDir)" + echo Post-build event started & + copy "$(ProjectDir)..\bella_engine_sdk\lib\bella_engine_sdk.dll" "$(TargetDir)" & + echo bella_engine_sdk.dll copied & + copy "$(ProjectDir)..\bella_engine_sdk\lib\dl_core.dll" "$(TargetDir)" & + echo dl_core.dll copied & + copy "$(ProjectDir)..\bella_engine_sdk\lib\dl_oidn_core.dll" "$(TargetDir)" & + echo dl_oidn_core.dll copied & + copy "$(ProjectDir)..\..\vcpkg\installed\x64-windows\bin\libzmq-mt-4_3_5.dll" "$(TargetDir)" & + echo libzmq-mt-4_3_5.dll copied & + copy "$(ProjectDir)..\..\vcpkg\installed\x64-windows\bin\libsodium.dll" "$(TargetDir)" & + echo libsodium.dll copied & + echo Post-build event finished + @@ -149,3 +161,4 @@ +