upd: on the way of debug

This commit is contained in:
2023-12-12 09:21:10 +00:00
parent c7f5e249c8
commit f9e1817f20
4 changed files with 25 additions and 11 deletions

View File

@ -5,10 +5,11 @@ BlockingStringStream &BlockingStringStream::getline(std::string &str,
std::unique_lock<std::mutex> lock(mutex);
// Wait until data is available
condition.wait(lock, [this] {
return internalStream.peek() != EOF && !is_writing;
});
str = "";
if (!(internalStream.peek() != EOF && !is_writing))
condition.wait(lock, [this] {
return internalStream.peek() != EOF && !is_writing;
});
str = "$FAILED$";
std::getline(internalStream, str, delim);
return *this;

View File

@ -1,5 +1,6 @@
#include "builtin-cli.h"
#include <cassert>
#include <iostream>
#include "bs-utility.h"
@ -19,7 +20,7 @@ void BookStoreMain(bool is_server, std::string config_dir) {
output.getline(tmp);
output >> SessionToken >> AuthenticationKey;
// debugPrint("SessionToken=", SessionToken,
// " AuthenticationKey=", AuthenticationKey);
// " AuthenticationKey=", AuthenticationKey);
std::string cmd;
output.getline(tmp);
while (getline(std::cin, cmd)) {
@ -35,12 +36,16 @@ void BookStoreMain(bool is_server, std::string config_dir) {
input.readlock();
input << "#Request " << SessionToken << " I-T-D" << ++cnt << " "
<< AuthenticationKey << ' ' << cmd << '\n';
assert(input.internalStream.peek() != EOF);
input.unreadlock();
// debugPrint("Sent Request ", cnt, " cmd=", cmd);
assert(input.is_writing == false);
debugPrint("Sent Request ", cnt, " cmd=", cmd);
std::string SessionToken;
std::string OperationToken;
int LineCounter;
output >> SessionToken >> OperationToken >> LineCounter;
debugPrint("Get the Head of response id=", OperationToken,
" LineCounter=", LineCounter);
// debugPrint("Get SessionToken=", SessionToken,
// " OperationToken=", OperationToken,
// " LineCounter=", LineCounter);

View File

@ -1,5 +1,6 @@
#include "schedule.h"
#include <cassert>
#include <iostream>
#include <random>
#include <sstream>
@ -11,7 +12,7 @@ void BookStoreBackEndClass::Run() {
std::mt19937 rnd(RndSeed);
while (true) {
input_ptr->getline(request_data, '\n');
// debugPrint("request_data=", request_data);
debugPrint("Get_request_data=", request_data);
if (request_data[1] == 'O') // #OpenSession [TempChannelID]
{
std::stringstream ss;
@ -31,7 +32,10 @@ void BookStoreBackEndClass::Run() {
(*output_ptr).readlock();
(*output_ptr) << TempChannelID << " IinitialOpt 1\n"
<< new_SessionToken << ' ' << new_AuthenticationKey << '\n';
assert((*output_ptr).internalStream.peek() != EOF);
(*output_ptr).unreadlock();
assert((*output_ptr).is_writing == false);
debugPrint("Sent Response Init");
} else if (request_data[1] == 'C') {
;
} else if (request_data[1] == '_') {
@ -53,7 +57,10 @@ void BookStoreBackEndClass::Run() {
(*output_ptr).readlock();
(*output_ptr) << SessionToken << ' ' << OperationToken << " 1\n"
<< cmd << '\n';
assert((*output_ptr).internalStream.peek() != EOF);
(*output_ptr).unreadlock();
assert((*output_ptr).is_writing == false);
debugPrint("Sent Response id=", OperationToken);
// debugPrint(SessionToken, ' ', OperationToken, " 1\n", cmd);
}
}