Skip to content

Simplify connect_to_host logic#5422

Open
KaganCanSit wants to merge 1 commit into
randombit:masterfrom
KaganCanSit:cleanup/tls-client-connect
Open

Simplify connect_to_host logic#5422
KaganCanSit wants to merge 1 commit into
randombit:masterfrom
KaganCanSit:cleanup/tls-client-connect

Conversation

@KaganCanSit

@KaganCanSit KaganCanSit commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Hello,

This PR addresses code simplifications following the RAII refactoring in #5399.

Simplify connect_to_host by removing the success flag and replacing the break/return pattern with an early return on successful connection. Initialize fd with invalid_socket() instead of 0 for semantic clarity.

Additionally, the following IIFE block has no const gain (Since psk cannot later move a const object using std::move, it is copied) and can be simplified. I can add this to the branch if desired. I am not sure this change.
IIFE:

auto psk = [this]() -> std::optional<Botan::secure_vector<uint8_t>> {
    auto psk_hex = get_arg_maybe("psk");
    if(psk_hex) {
        return Botan::hex_decode_locked(psk_hex.value());
    } else {
        return {};
    }
}();

Change:

std::optional<Botan::secure_vector<uint8_t>> psk{};
if(const auto psk_hex = get_arg_maybe("psk")) {
    psk = Botan::hex_decode_locked(psk_hex.value());
}

Regards.

@KaganCanSit

KaganCanSit commented Mar 8, 2026

Copy link
Copy Markdown
Contributor Author
src/cli/tls_client.cpp:400:22: warning: Value stored to 'fd' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
  400 |          socket_type fd = invalid_socket();
      |                      ^~   ~~~~~~~~~~~~~~~~
src/cli/tls_client.cpp:400:22: note: Value stored to 'fd' during its initialization is never read
  400 |          socket_type fd = invalid_socket();
      |                      ^~   ~~~~~~~~~~~~~~~~
socket_type fd = invalid_socket();
for(const addrinfo* rp = res.get(); rp != nullptr; rp = rp->ai_next) {

Clang-tidy not like this, I changing right now.

Updates:
24.05.2026 - Rebase master branch.

@KaganCanSit
KaganCanSit force-pushed the cleanup/tls-client-connect branch from 83a659a to 6594524 Compare March 8, 2026 19:45
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 91.922% (+1.7%) from 90.184%
when pulling 6594524 on KaganCanSit:cleanup/tls-client-connect
into cdaa9c0 on randombit:master.

@KaganCanSit
KaganCanSit force-pushed the cleanup/tls-client-connect branch from 6594524 to d6f8bff Compare May 24, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants