Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ljcui committed Jan 17, 2025
1 parent 686ff99 commit 335dd91
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/bolt/blocking_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace bolt {
template <typename T>
class BlockingQueue {
public:
void Push(T const& value) {
void Push(T&& value) {
{
std::unique_lock<std::mutex> lock(mutex_);
queue_.push_front(value);
queue_.push_front(std::move(value));
}
condition_.notify_one();
}
Expand Down
2 changes: 1 addition & 1 deletion src/bolt/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void BoltConnection::ReadChunkSizeDone(const boost::system::error_code& ec) {
}
LOG_DEBUG() << FMA_FMT("msg: {}, fields: {}",
ToString(tag), Print(fields));
handle_(*this, tag, std::move(fields));
handle_(*this, tag, std::move(fields), std::move(chunk_));
} catch (const std::exception& e) {
LOG_ERROR() << "Exception in bolt connection: " << e.what();
Close();
Expand Down
2 changes: 1 addition & 1 deletion src/bolt/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class BoltConnection
void DoSend();

std::function<void(BoltConnection& conn, BoltMsg msg,
std::vector<std::any> fields)> handle_;
std::vector<std::any> fields, std::vector<uint8_t> raw_data)> handle_;
const uint8_t bolt_magic_[4] = {0x60, 0x60, 0xB0, 0x17};
const uint8_t ws_magic_[4] = {'G', 'E', 'T', ' '}; // websocket
uint8_t buffer4_[4] = {0};
Expand Down
11 changes: 7 additions & 4 deletions src/server/bolt_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,8 @@ void BoltFSM(std::shared_ptr<BoltConnection> conn) {
LOG_DEBUG() << FMA_FMT("bolt fsm thread[conn_id:{}] exit.", conn_id);
}

std::function<void(bolt::BoltConnection &conn, bolt::BoltMsg msg,
std::vector<std::any> fields)> BoltHandler =
[](BoltConnection& conn, BoltMsg msg, std::vector<std::any> fields) {
std::function BoltHandler =
[](BoltConnection& conn, BoltMsg msg, std::vector<std::any> fields, std::vector<uint8_t> raw_data) {
if (msg == BoltMsg::Hello) {
if (fields.size() != 1) {
LOG_ERROR() << "Hello msg fields size error, size: " << fields.size();
Expand Down Expand Up @@ -309,7 +308,11 @@ std::function<void(bolt::BoltConnection &conn, bolt::BoltMsg msg,
msg == BoltMsg::Commit ||
msg == BoltMsg::Rollback) {
auto session = (BoltSession*)conn.GetContext();
session->msgs.Push({msg, std::move(fields)});
BoltMsgDetail detail;
detail.type = msg;
detail.fields = std::move(fields);
detail.raw_data = std::move(raw_data);
session->msgs.Push(std::move(detail));
} else if (msg == BoltMsg::Reset) {
auto session = (BoltSession*)conn.GetContext();
session->state = SessionState::INTERRUPTED;
Expand Down
1 change: 1 addition & 0 deletions src/server/bolt_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct BoltMsgDetail {
BoltMsg type;
std::vector<std::any> fields;
int64_t n = -1;
std::vector<uint8_t> raw_data;
};

struct BoltSession {
Expand Down

0 comments on commit 335dd91

Please sign in to comment.