LCOV - code coverage report
Current view: top level - prinbee/network - binary_server.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 21 0
Test Date: 2025-06-19 11:28:46 Functions: 0.0 % 3 0
Legend: Lines: hit not hit

            Line data    Source code
       1              : // Copyright (c) 2016-2025  Made to Order Software Corp.  All Rights Reserved
       2              : //
       3              : // https://snapwebsites.org/project/prinbee
       4              : // contact@m2osw.com
       5              : //
       6              : // This program is free software: you can redistribute it and/or modify
       7              : // it under the terms of the GNU General Public License as published by
       8              : // the Free Software Foundation, either version 3 of the License, or
       9              : // (at your option) any later version.
      10              : //
      11              : // This program is distributed in the hope that it will be useful,
      12              : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              : // GNU General Public License for more details.
      15              : //
      16              : // You should have received a copy of the GNU General Public License
      17              : // along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18              : 
      19              : /** \file
      20              :  * \brief Messenger for the prinbee daemon.
      21              :  *
      22              :  * The Prinbee daemon has a normal messenger connection. This is used to
      23              :  * find the daemons and connect to them. The clients make use of a
      24              :  * direct connection so communication can happen with large binary data
      25              :  * (i.e. large files are to be sent to the backends).
      26              :  */
      27              : 
      28              : 
      29              : // self
      30              : //
      31              : #include    "prinbee/network/binary_server.h"
      32              : 
      33              : //#include    "prinbeed.h"
      34              : #include    "prinbee/network/binary_server_client.h"
      35              : 
      36              : 
      37              : // snaplogger
      38              : //
      39              : #include    <snaplogger/message.h>
      40              : 
      41              : 
      42              : // eventdispatcher
      43              : //
      44              : #include    <eventdispatcher/communicator.h>
      45              : 
      46              : 
      47              : //// communicatord
      48              : ////
      49              : //#include    <communicatord/names.h>
      50              : 
      51              : 
      52              : // last include
      53              : //
      54              : #include    <snapdev/poison.h>
      55              : 
      56              : 
      57              : 
      58              : namespace prinbee
      59              : {
      60              : 
      61              : 
      62              : /** \class binary_server
      63              :  * \brief Handle messages from clients, proxies, Prinbee daemons.
      64              :  *
      65              :  * This class is an implementation of the event dispatcher TCP server
      66              :  * connection used to accept connections used to handle binary messages.
      67              :  *
      68              :  * The class is used in the proxy services and the prinbee daemons.
      69              :  *
      70              :  * Once a connection is obtained, it creates a binary_client object.
      71              :  *
      72              :  * \warning
      73              :  * This class is considered private to the prinbee environment.
      74              :  */
      75              : 
      76              : 
      77              : 
      78              : /** \brief A binary_server to listen for connection requests.
      79              :  *
      80              :  * This connection is used to listen for new connection requests between
      81              :  * clients, proxies, and daemons using binary messages which are much
      82              :  * more compact than the communicator daemon messages that use text.
      83              :  *
      84              :  * \param[in] a  The address to listen on, it can be ANY.
      85              :  * \param[in] opts  The options received from the command line.
      86              :  */
      87            0 : binary_server::binary_server(addr::addr const & a)
      88            0 :     : tcp_server_connection(a, std::string(), std::string())
      89              : {
      90            0 : }
      91              : 
      92              : 
      93            0 : binary_server::~binary_server()
      94              : {
      95            0 : }
      96              : 
      97              : 
      98            0 : void binary_server::process_accept()
      99              : {
     100              :     // a new client just connected, create a new service_connection
     101              :     // object and add it to the ed::communicator object.
     102              :     //
     103            0 :     ed::tcp_bio_client::pointer_t const new_client(accept());
     104            0 :     if(new_client == nullptr)
     105              :     {
     106              :         // an error occurred, report in the logs
     107              :         //
     108            0 :         int const e(errno);
     109            0 :         SNAP_LOG_ERROR
     110            0 :             << "somehow accept() of a binary connection failed with errno: "
     111              :             << e
     112              :             << " -- "
     113            0 :             << strerror(e)
     114              :             << SNAP_LOG_SEND;
     115            0 :         return;
     116              :     }
     117              : 
     118            0 :     binary_server_client::pointer_t service(std::make_shared<binary_server_client>(new_client));
     119            0 :     addr::addr const remote_addr(service->get_remote_address());
     120            0 :     service->set_name(
     121              :               "in: "
     122            0 :             + remote_addr.to_ipv4or6_string(addr::STRING_IP_BRACKET_ADDRESS | addr::STRING_IP_PORT));
     123              : 
     124            0 :     if(!ed::communicator::instance()->add_connection(service))
     125              :     {
     126              :         // this should never happen here since each new creates a
     127              :         // new pointer
     128              :         //
     129            0 :         SNAP_LOG_ERROR
     130              :             << "new client \""
     131            0 :             << service->get_name()
     132              :             << "\" connection could not be added to the ed::communicator list of connections."
     133              :             << SNAP_LOG_SEND;
     134              :     }
     135            0 : }
     136              : 
     137              : 
     138              : 
     139              : } // namespace prinbee
     140              : // vim: ts=4 sw=4 et
        

Generated by: LCOV version 2.0-1

Snap C++ | List of projects | List of versions