Skip to content

Commit

Permalink
websocket: Rename wlogger to websocket_logger
Browse files Browse the repository at this point in the history
Previous name was useful when it's used locally in translation unit. The
new name is exposed in a header and should be more unique.
  • Loading branch information
p12tic committed Feb 3, 2025
1 parent c9b7a5f commit 7f30f19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/seastar/websocket/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected:

std::string sha1_base64(std::string_view source);

extern logger wlogger;
extern logger websocket_logger;

/// @}
}
10 changes: 5 additions & 5 deletions src/websocket/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace seastar::experimental::websocket {

sstring magic_key_suffix = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
logger wlogger("websocket");
logger websocket_logger("websocket");

future<> connection::handle_ping() {
// TODO
Expand Down Expand Up @@ -109,14 +109,14 @@ future<> connection::read_one() {
case opcodes::BINARY:
return _input_buffer.push_eventually(_websocket_parser.result());
case opcodes::CLOSE:
wlogger.debug("Received close frame.");
websocket_logger.debug("Received close frame.");
// datatracker.ietf.org/doc/html/rfc6455#section-5.5.1
return close(true);
case opcodes::PING:
wlogger.debug("Received ping frame.");
websocket_logger.debug("Received ping frame.");
return handle_ping();
case opcodes::PONG:
wlogger.debug("Received pong frame.");
websocket_logger.debug("Received pong frame.");
return handle_pong();
default:
// Invalid - do nothing.
Expand All @@ -125,7 +125,7 @@ future<> connection::read_one() {
} else if (_websocket_parser.eof()) {
return close(false);
}
wlogger.debug("Reading from socket has failed.");
websocket_logger.debug("Reading from socket has failed.");
return close(true);
});
}
Expand Down
14 changes: 7 additions & 7 deletions src/websocket/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ future<stop_iteration> server::accept_one(server_socket &listener) {
auto conn = std::make_unique<server_connection>(*this, std::move(ar.connection));
(void)try_with_gate(_task_gate, [conn = std::move(conn)]() mutable {
return conn->process().finally([conn = std::move(conn)] {
wlogger.debug("Connection is finished");
websocket_logger.debug("Connection is finished");
});
}).handle_exception_type([](const gate_closed_exception &e) {});
return make_ready_future<stop_iteration>(stop_iteration::no);
}).handle_exception_type([](const std::system_error &e) {
// We expect a ECONNABORTED when server::stop is called,
// no point in warning about that.
if (e.code().value() != ECONNABORTED) {
wlogger.error("accept failed: {}", e);
websocket_logger.error("accept failed: {}", e);
}
return make_ready_future<stop_iteration>(stop_iteration::yes);
}).handle_exception([](std::exception_ptr ex) {
wlogger.info("accept failed: {}", ex);
websocket_logger.info("accept failed: {}", ex);
return make_ready_future<stop_iteration>(stop_iteration::yes);
});
}
Expand Down Expand Up @@ -102,7 +102,7 @@ void server_connection::on_new_connection() {

future<> server_connection::process() {
return when_all_succeed(read_loop(), response_loop()).discard_result().handle_exception([] (const std::exception_ptr& e) {
wlogger.debug("Processing failed: {}", e);
websocket_logger.debug("Processing failed: {}", e);
});
}

Expand Down Expand Up @@ -131,17 +131,17 @@ future<> server_connection::read_http_upgrade_request() {
}
this->_handler = this->_server._handlers[subprotocol];
this->_subprotocol = subprotocol;
wlogger.debug("Sec-WebSocket-Protocol: {}", subprotocol);
websocket_logger.debug("Sec-WebSocket-Protocol: {}", subprotocol);

sstring sec_key = req->get_header("Sec-Websocket-Key");
sstring sec_version = req->get_header("Sec-Websocket-Version");

sstring sha1_input = sec_key + magic_key_suffix;

wlogger.debug("Sec-Websocket-Key: {}, Sec-Websocket-Version: {}", sec_key, sec_version);
websocket_logger.debug("Sec-Websocket-Key: {}, Sec-Websocket-Version: {}", sec_key, sec_version);

std::string sha1_output = sha1_base64(sha1_input);
wlogger.debug("SHA1 output: {} of size {}", sha1_output, sha1_output.size());
websocket_logger.debug("SHA1 output: {} of size {}", sha1_output, sha1_output.size());

co_await _write_buf.write(http_upgrade_reply_template);
co_await _write_buf.write(sha1_output);
Expand Down

0 comments on commit 7f30f19

Please sign in to comment.