fix: add notify when unreadlock
This commit is contained in:
@ -55,7 +55,7 @@ BlockingStringStream &BlockingStringStream::operator<<(const T &val) {
|
|||||||
}
|
}
|
||||||
internalStream << val;
|
internalStream << val;
|
||||||
}
|
}
|
||||||
condition.notify_one();
|
condition.notify_all();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ BlockingStringStream &BlockingStringStream::getline(std::string &str,
|
|||||||
condition.wait(lock, [this] {
|
condition.wait(lock, [this] {
|
||||||
return internalStream.peek() != EOF && !is_writing;
|
return internalStream.peek() != EOF && !is_writing;
|
||||||
});
|
});
|
||||||
|
str = "";
|
||||||
std::getline(internalStream, str, delim);
|
std::getline(internalStream, str, delim);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -53,4 +53,7 @@ void debugPrint() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BlockingStringStream::readlock() { is_writing = true; }
|
void BlockingStringStream::readlock() { is_writing = true; }
|
||||||
void BlockingStringStream::unreadlock() { is_writing = false; }
|
void BlockingStringStream::unreadlock() {
|
||||||
|
is_writing = false;
|
||||||
|
condition.notify_all();
|
||||||
|
}
|
@ -18,8 +18,8 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
|||||||
std::string SessionToken, AuthenticationKey, tmp;
|
std::string SessionToken, AuthenticationKey, tmp;
|
||||||
output.getline(tmp);
|
output.getline(tmp);
|
||||||
output >> SessionToken >> AuthenticationKey;
|
output >> SessionToken >> AuthenticationKey;
|
||||||
debugPrint("SessionToken=", SessionToken,
|
// debugPrint("SessionToken=", SessionToken,
|
||||||
" AuthenticationKey=", AuthenticationKey);
|
// " AuthenticationKey=", AuthenticationKey);
|
||||||
std::string cmd;
|
std::string cmd;
|
||||||
output.getline(tmp);
|
output.getline(tmp);
|
||||||
while (getline(std::cin, cmd)) {
|
while (getline(std::cin, cmd)) {
|
||||||
@ -36,6 +36,7 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
|||||||
input << "#Request " << SessionToken << " I-T-D" << ++cnt << " "
|
input << "#Request " << SessionToken << " I-T-D" << ++cnt << " "
|
||||||
<< AuthenticationKey << ' ' << cmd << '\n';
|
<< AuthenticationKey << ' ' << cmd << '\n';
|
||||||
input.unreadlock();
|
input.unreadlock();
|
||||||
|
// debugPrint("Sent Request ", cnt, " cmd=", cmd);
|
||||||
std::string SessionToken;
|
std::string SessionToken;
|
||||||
std::string OperationToken;
|
std::string OperationToken;
|
||||||
int LineCounter;
|
int LineCounter;
|
||||||
@ -47,7 +48,9 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
|||||||
for (int i = 0; i < LineCounter; i++) {
|
for (int i = 0; i < LineCounter; i++) {
|
||||||
output.getline(tmp);
|
output.getline(tmp);
|
||||||
std::cout << tmp << std::endl;
|
std::cout << tmp << std::endl;
|
||||||
|
// std::cerr << tmp << std::endl;
|
||||||
}
|
}
|
||||||
|
std::cout.flush();
|
||||||
}
|
}
|
||||||
input.readlock();
|
input.readlock();
|
||||||
input << "#CloseSession " << SessionToken << ' ' << AuthenticationKey
|
input << "#CloseSession " << SessionToken << ' ' << AuthenticationKey
|
||||||
|
@ -11,7 +11,7 @@ void BookStoreBackEndClass::Run() {
|
|||||||
std::mt19937 rnd(RndSeed);
|
std::mt19937 rnd(RndSeed);
|
||||||
while (true) {
|
while (true) {
|
||||||
input_ptr->getline(request_data, '\n');
|
input_ptr->getline(request_data, '\n');
|
||||||
debugPrint("request_data=", request_data);
|
// debugPrint("request_data=", request_data);
|
||||||
if (request_data[1] == 'O') // #OpenSession [TempChannelID]
|
if (request_data[1] == 'O') // #OpenSession [TempChannelID]
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -37,7 +37,7 @@ void BookStoreBackEndClass::Run() {
|
|||||||
} else if (request_data[1] == '_') {
|
} else if (request_data[1] == '_') {
|
||||||
;
|
;
|
||||||
} else if (request_data[1] == 'S') {
|
} else if (request_data[1] == 'S') {
|
||||||
;
|
return;
|
||||||
} else if (request_data[1] == 'R') {
|
} else if (request_data[1] == 'R') {
|
||||||
std::stringstream ss(request_data);
|
std::stringstream ss(request_data);
|
||||||
std::string SessionToken;
|
std::string SessionToken;
|
||||||
@ -50,12 +50,11 @@ void BookStoreBackEndClass::Run() {
|
|||||||
// debugPrint("SessionToken=", SessionToken,
|
// debugPrint("SessionToken=", SessionToken,
|
||||||
// " OperationToken=", OperationToken,
|
// " OperationToken=", OperationToken,
|
||||||
// " OuthenticationKey=", OuthenticationKey, " cmd=", cmd);
|
// " OuthenticationKey=", OuthenticationKey, " cmd=", cmd);
|
||||||
// std::cerr << "[]" << SessionToken << ' ' << OperationToken
|
|
||||||
// << " 1\nECHO: " << cmd << '\n';
|
|
||||||
(*output_ptr).readlock();
|
(*output_ptr).readlock();
|
||||||
(*output_ptr) << SessionToken << ' ' << OperationToken
|
(*output_ptr) << SessionToken << ' ' << OperationToken << " 1\n"
|
||||||
<< " 1\nECHO: " << cmd << '\n';
|
<< cmd << '\n';
|
||||||
(*output_ptr).unreadlock();
|
(*output_ptr).unreadlock();
|
||||||
|
// debugPrint(SessionToken, ' ', OperationToken, " 1\n", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user