Skip to content
Snippets Groups Projects
Commit 49b52a97 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Release recv lock during processing

parent 9d562619
No related branches found
No related tags found
1 merge request!37Resolves #83 net performance, partially
...@@ -416,14 +416,18 @@ void Peer::data() { ...@@ -416,14 +416,18 @@ void Peer::data() {
} }
recv_buf_.buffer_consumed(rc); recv_buf_.buffer_consumed(rc);
lk.unlock();
LOG(INFO) << "Received " << rc << " bytes";
// No thread currently processing messages so start one
if (is_waiting_) {
pool.push([](int id, Peer *p) { pool.push([](int id, Peer *p) {
p->_data(); p->_data();
//p->is_waiting_ = true; //p->is_waiting_ = true;
}, this); }, this);
is_waiting_ = false;
}
lk.unlock();
LOG(INFO) << "Received " << rc << " bytes";
} }
bool Peer::_data() { bool Peer::_data() {
...@@ -440,7 +444,7 @@ bool Peer::_data() { ...@@ -440,7 +444,7 @@ bool Peer::_data() {
msgpack::object_handle msg; msgpack::object_handle msg;
while (recv_buf_.next(msg)) { while (recv_buf_.next(msg)) {
// CHECK Safe to unlock here? // CHECK Safe to unlock here?
//lk.unlock(); lk.unlock();
ws_read_header_ = false; ws_read_header_ = false;
msgpack::object obj = msg.get(); msgpack::object obj = msg.get();
if (status_ != kConnected) { if (status_ != kConnected) {
...@@ -463,7 +467,7 @@ bool Peer::_data() { ...@@ -463,7 +467,7 @@ bool Peer::_data() {
disp_->dispatch(*this, obj); disp_->dispatch(*this, obj);
// Relock before next loop of while // Relock before next loop of while
//lk.lock(); lk.lock();
if (scheme_ == ftl::URI::SCHEME_WS && recv_buf_.nonparsed_size() > 0) { if (scheme_ == ftl::URI::SCHEME_WS && recv_buf_.nonparsed_size() > 0) {
wsheader_type ws; wsheader_type ws;
...@@ -473,6 +477,7 @@ bool Peer::_data() { ...@@ -473,6 +477,7 @@ bool Peer::_data() {
ws_read_header_ = true; ws_read_header_ = true;
} }
} }
is_waiting_ = true; // Can start another thread...
return false; return false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment