Skip to content

Commit 12419ae

Browse files
committed
Cache result of api_config->use_protocol_version()
1 parent f07c2e2 commit 12419ae

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/tcp_server.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,18 @@ void client_session::handle_read_feedparams(
378378
// --- protocol negotiation ---
379379

380380
// check request validity
381-
if (request_protocol_version / 100 >
382-
api_config::get_instance()->use_protocol_version() / 100) {
383-
send_status_message("LSL/" +
384-
std::to_string(api_config::get_instance()->use_protocol_version()) +
385-
" 505 Version not supported");
381+
auto cfg_proto_version = api_config::get_instance()->use_protocol_version();
382+
if (request_protocol_version / 100 > cfg_proto_version / 100) {
383+
send_status_message(
384+
"LSL/" + std::to_string(cfg_proto_version) + " 505 Version not supported");
386385
DLOG_F(WARNING, "%p Got a request for a too new protocol version", this);
387386
return;
388387
}
389388
auto serv = serv_.lock();
390389
if (!serv) return;
391390
auto &info = serv->info_;
392391
if (!request_uid.empty() && request_uid != info->uid()) {
393-
send_status_message("LSL/" +
394-
to_string(api_config::get_instance()->use_protocol_version()) +
395-
" 404 Not found");
392+
send_status_message("LSL/" + to_string(cfg_proto_version) + " 404 Not found");
396393
return;
397394
}
398395

@@ -447,8 +444,7 @@ void client_session::handle_read_feedparams(
447444
lsl::Endianness use_byte_order = LSL_BYTE_ORDER;
448445

449446
// use least common denominator data protocol version
450-
data_protocol_version_ = std::min(
451-
api_config::get_instance()->use_protocol_version(), client_protocol_version);
447+
data_protocol_version_ = std::min(cfg_proto_version, client_protocol_version);
452448
// downgrade to 1.00 (portable binary format) if an unsupported binary conversion is
453449
// involved
454450
if (info->channel_format() != cft_string && info->channel_bytes() != client_value_size)
@@ -480,8 +476,7 @@ void client_session::handle_read_feedparams(
480476

481477
// send the response
482478
std::ostream response_stream(&feedbuf_);
483-
response_stream << "LSL/" << api_config::get_instance()->use_protocol_version()
484-
<< " 200 OK\r\n";
479+
response_stream << "LSL/" << cfg_proto_version << " 200 OK\r\n";
485480
response_stream << "UID: " << info->uid() << "\r\n";
486481
response_stream << "Byte-Order: " << use_byte_order << "\r\n";
487482
response_stream << "Suppress-Subnormals: " << client_suppress_subnormals << "\r\n";

0 commit comments

Comments
 (0)