LCOV - code coverage report
Current view: top level - wirestead/transport/tcp_server - boost_tcp_acceptor.cc (source / functions) Coverage Total Hit
Test: Wirestead Coverage Report Lines: 100.0 % 15 15
Test Date: 2026-08-30 10:35:09 Functions: 100.0 % 7 7
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50.0 % 2 1

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright 2025 Jinwoo Sung
       3                 :             :  *
       4                 :             :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :             :  * you may not use this file except in compliance with the License.
       6                 :             :  * You may obtain a copy of the License at
       7                 :             :  *
       8                 :             :  *     http://www.apache.org/licenses/LICENSE-2.0
       9                 :             :  *
      10                 :             :  * Unless required by applicable law or agreed to in writing, software
      11                 :             :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :             :  * See the License for the specific language governing permissions and
      14                 :             :  * limitations under the License.
      15                 :             :  */
      16                 :             : 
      17                 :             : #include "wirestead/transport/tcp_server/boost_tcp_acceptor.hpp"
      18                 :             : 
      19                 :             : namespace wirestead {
      20                 :             : namespace transport {
      21                 :             : 
      22                 :             : namespace net = boost::asio;
      23                 :             : 
      24                 :         136 : BoostTcpAcceptor::BoostTcpAcceptor(net::io_context& ioc) : acceptor_(ioc) {}
      25                 :             : 
      26                 :         126 : void BoostTcpAcceptor::open(const net::ip::tcp& protocol, boost::system::error_code& ec) {
      27                 :         126 :   acceptor_.open(protocol, ec);
      28         [ +  - ]:         126 :   if (!ec) {
      29                 :             :     // Set SO_REUSEADDR to allow immediate port reuse after server shutdown
      30                 :             :     // This prevents "Address already in use" errors in tests and quick restarts
      31                 :         126 :     acceptor_.set_option(net::socket_base::reuse_address(true), ec);
      32                 :             :   }
      33                 :         126 : }
      34                 :             : 
      35                 :         128 : void BoostTcpAcceptor::bind(const net::ip::tcp::endpoint& endpoint, boost::system::error_code& ec) {
      36                 :         128 :   acceptor_.bind(endpoint, ec);
      37                 :         128 : }
      38                 :             : 
      39                 :         125 : void BoostTcpAcceptor::listen(int backlog, boost::system::error_code& ec) { acceptor_.listen(backlog, ec); }
      40                 :             : 
      41                 :        2305 : bool BoostTcpAcceptor::is_open() const { return acceptor_.is_open(); }
      42                 :             : 
      43                 :         126 : void BoostTcpAcceptor::close(boost::system::error_code& ec) { acceptor_.close(ec); }
      44                 :             : 
      45                 :        2041 : void BoostTcpAcceptor::async_accept(
      46                 :             :     std::function<void(const boost::system::error_code&, net::ip::tcp::socket)> handler) {
      47                 :        2041 :   acceptor_.async_accept(std::move(handler));
      48                 :        2041 : }
      49                 :             : 
      50                 :             : }  // namespace transport
      51                 :             : }  // namespace wirestead
        

Generated by: LCOV version 2.0-1