upd: on the way of debug
This commit is contained in:
@ -37,12 +37,12 @@ class BlockingStringStream {
|
||||
std::stringstream internalStream;
|
||||
void readlock();
|
||||
void unreadlock();
|
||||
std::atomic<bool> is_writing = false;
|
||||
|
||||
private:
|
||||
std::mutex mutex;
|
||||
std::mutex custom_mutex;
|
||||
std::condition_variable condition;
|
||||
std::atomic<bool> is_writing = false;
|
||||
};
|
||||
// Implementation of operator<<
|
||||
template <typename T>
|
||||
@ -65,9 +65,10 @@ BlockingStringStream &BlockingStringStream::operator>>(T &val) {
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
|
||||
// Wait until data is available
|
||||
condition.wait(lock, [this] {
|
||||
return internalStream.peek() != EOF && !is_writing;
|
||||
});
|
||||
if (!(internalStream.peek() != EOF && !is_writing))
|
||||
condition.wait(lock, [this] {
|
||||
return internalStream.peek() != EOF && !is_writing;
|
||||
});
|
||||
|
||||
internalStream >> val;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user