From ffb1a5f788e05ae6d605e8d25784e2e66f2824a4 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Tue, 12 Dec 2023 07:29:45 +0000 Subject: [PATCH] upd: ready to fix read in half way of write --- backend/include/bs-utility.h | 5 ++++- backend/src/bs-utility.cpp | 5 ++++- backend/src/builtin-cli.cpp | 11 +++++++++-- backend/src/schedule.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/backend/include/bs-utility.h b/backend/include/bs-utility.h index 325cce7..c9e5cfe 100644 --- a/backend/include/bs-utility.h +++ b/backend/include/bs-utility.h @@ -35,9 +35,12 @@ class BlockingStringStream { BlockingStringStream &operator>>(T &val); BlockingStringStream &getline(std::string &str, char delim = '\n'); std::stringstream internalStream; + void lock(); + void unlock(); private: std::mutex mutex; + std::mutex custom_mutex; std::condition_variable condition; }; // Implementation of operator<< @@ -82,7 +85,7 @@ class ReadWriteLock { void endWrite(); }; class SessionClass { - public: + public: std::stack login_stack; std::string SessionToken; std::string OuthorizationKey; diff --git a/backend/src/bs-utility.cpp b/backend/src/bs-utility.cpp index a695521..e584e4a 100644 --- a/backend/src/bs-utility.cpp +++ b/backend/src/bs-utility.cpp @@ -48,4 +48,7 @@ void debugPrint() { BookStore_ZYM::debug_Print_Mutex.lock(); std::cerr << std::endl; BookStore_ZYM::debug_Print_Mutex.unlock(); -} \ No newline at end of file +} + +void BlockingStringStream::lock() { custom_mutex.lock(); } +void BlockingStringStream::unlock() { custom_mutex.unlock(); } \ No newline at end of file diff --git a/backend/src/builtin-cli.cpp b/backend/src/builtin-cli.cpp index 6d2b0db..c77736c 100644 --- a/backend/src/builtin-cli.cpp +++ b/backend/src/builtin-cli.cpp @@ -28,8 +28,15 @@ void BookStoreMain(bool is_server, std::string config_dir) { } input << "#Request " << SessionToken << " I-T-D " << AuthenticationKey << ' ' << cmd << '\n'; - output.getline(tmp); - std::cout << tmp << std::endl; + std::string SessionToken; + std::string OperationToken; + int LineCounter; + continue; + output >> SessionToken >> OperationToken >> LineCounter; + for (int i = 0; i < LineCounter; i++) { + output.getline(tmp); + std::cout << tmp << std::endl; + } } input << "#CloseSession " << SessionToken << ' ' << AuthenticationKey << '\n'; diff --git a/backend/src/schedule.cpp b/backend/src/schedule.cpp index b0e434e..c84c61c 100644 --- a/backend/src/schedule.cpp +++ b/backend/src/schedule.cpp @@ -1,5 +1,6 @@ #include "schedule.h" +#include #include #include @@ -29,6 +30,29 @@ void BookStoreBackEndClass::Run() { session_map[new_SessionToken] = new_session; (*output_ptr) << TempChannelID << " IinitialOpt 1\n" << new_SessionToken << ' ' << new_AuthenticationKey << '\n'; + } else if (request_data[1] == 'C') { + ; + } else if (request_data[1] == '_') { + ; + } else if (request_data[1] == 'S') { + ; + } else if (request_data[1] == 'R') { + std::stringstream ss(request_data); + std::string SessionToken; + std::string OperationToken; + std::string OuthenticationKey; + std::string cmd; + ss >> cmd >> SessionToken >> OperationToken >> OuthenticationKey; + ss.get(); + std::getline(ss, cmd); + debugPrint("SessionToken=", SessionToken, + " OperationToken=", OperationToken, + " OuthenticationKey=", OuthenticationKey, " cmd=", cmd); + // (*output_ptr) << SessionToken << ' ' << OperationToken << " 0\n"; + (*output_ptr) << SessionToken << ' ' << OperationToken + << " 1\nECHO: " << cmd << '\n'; + // std::cerr << "[]" << SessionToken << ' ' << OperationToken + // << " 1\nECHO: " << cmd << '\n'; } } } \ No newline at end of file