demo/nix/prefork-server.cpp
/*!
     * @brief Entry point for worker processes.
     */
@brief Entry point for worker processes.
@brief Entry point for worker processes .
int run (Server& server)
    try
    {
        Worker worker(server);
        int stream = -1;
        do {
            std::cout
                << "[" << ::getpid() << "] "
                << "Waiting for a connection."
                << std::endl;
            stream = server.accept_connection();
            if (stream == -1)
            {
                std::cout
                    << "[" << ::getpid() << "] "
                    << "Failed to accept: '" << ::strerror(errno) << "'."
                    << std::endl;
                return (EXIT_FAILURE);
            }
            std::cout
                << "[" << ::getpid() << "] "
                << "Received a connection (socket=" << stream << ")."
                << std::endl;
        }
        while (worker.handle(stream));
        std::cout
            << "[" << ::getpid() << "] "
            << "Over and out";
        if (!worker.achieved_quota()) {
            std::cout << " (early exit)";
        }
        std::cout << "!" << std::endl;
        ::close(stream);
        return (EXIT_SUCCESS);
    }
    catch (const std::exception& error)
    {
        std::cerr
            << "[" << ::getpid() << "] "
            << "Handler failed (" << error.what() << ")."
            << std::endl;
        return (EXIT_FAILURE);
    }
    catch (...)
    {
        std::cerr
            << "[" << ::getpid() << "] "
            << "Handler crashed!"
            << std::endl;
        return (EXIT_FAILURE);
    }
int run ( Server & server ) try { Worker worker ( server ) ; int stream = -1 ; do { std :: cout << " " << :: getpid ( ) << " " << " " << std :: endl ; stream = server . accept_connection ( ) ; if ( stream == -1 ) { std :: cout << " " << :: getpid ( ) << " " << " " << :: strerror ( errno ) << " " << std :: endl ; return ( EXIT_FAILURE ) ; } std :: cout << " " << :: getpid ( ) << " " << " " << stream << " " << std :: endl ; } while ( worker . handle ( stream ) ) ; std :: cout << " " << :: getpid ( ) << " " << " " ; if ( ! worker . achieved_quota ( ) ) { std :: cout << " " ; } std :: cout << " " << std :: endl ; :: close ( stream ) ; return ( EXIT_SUCCESS ) ; } catch ( const std :: exception & error ) { std :: cerr << " " << :: getpid ( ) << " " << " " << error . what ( ) << " " << std :: endl ; return ( EXIT_FAILURE ) ; } catch ( ... ) { std :: cerr << " " << :: getpid ( ) << " " << " " << std :: endl ; return ( EXIT_FAILURE ) ; }
@brief Entry point for worker processes.
@brief Entry point for worker processes .
// Accept connections until the quota is satisfied // or the handler requests an early exit. // Wait for connection from remote peer. // Handle client connection. // Finished!