<commit_before>#ifndef CACHELOT_NET_TCP_SERVER_H_INCLUDED
#define CACHELOT_NET_TCP_SERVER_H_INCLUDED

//
//  (C) Copyright 2015 <NAME>
//
//  Distributed under the terms of Simplified BSD License
//  see LICENSE file


#ifndef CACHELOT_NETWORK_H_INCLUDED
#  include <cachelot/network.h>
#endif

/**
 * @ingroup net
 * @{
 */

namespace cachelot { namespace net {

    /**
     * tcp_server is a server for TCP/IP protocol family
     *
     * @tparam Impl -           Actual TCP Server implementation class, must be derived from tcp_server
     *                          tcp_server expects that Impl class provides following functions:
     *                          `ConnectionType * new_connection()` to create new connections
     *                          `delete_connection(ConnectionType *)` to delete broken connections
     * @tparam ConnectionType - class representing connections of this TCP Server
     *                          tcp_server expects that ConnectionType provides function
     *                          `void run()` that will be called after establishing connection
     *                           with the client
     */
    template <class Impl, class ConnectionType>
    class tcp_server {
        typedef tcp_server<Impl, ConnectionType> this_type;
    public:
        /// constructor
        explicit tcp_server(io_service & ios)
            : m_ios(ios)
            , m_acceptor(ios) {
            static_assert(std::is_base_of<this_type, Impl>::value, "TCP Server implementation must be derived from tcp_server");
        }

        tcp_server(const tcp_server &) = delete;
        tcp_server & operator= (const tcp_server &) = delete;

        /// start accept connections
        void start(const tcp::endpoint bind_addr);

        /// start accept connections
        void start(uint16 port) {
            tcp::endpoint bind_addr(ip::address_v4::any(), port);
            start(bind_addr);<commit_msg>Added SO_REUSEADDR option to avoid "Address already in use" error after server restart<commit_after>#ifndef CACHELOT_NET_TCP_SERVER_H_INCLUDED
#define CACHELOT_NET_TCP_SERVER_H_INCLUDED

//
//  (C) Copyright 2015 <NAME>
//
//  Distributed under the terms of Simplified BSD License
//  see LICENSE file


#ifndef CACHELOT_NETWORK_H_INCLUDED
#  include <cachelot/network.h>
#endif

/**
 * @ingroup net
 * @{
 */

namespace cachelot { namespace net {

    /**
     * tcp_server is a server for TCP/IP protocol family
     *
     * @tparam Impl -           Actual TCP Server implementation class, must be derived from tcp_server
     *                          tcp_server expects that Impl class provides following functions:
     *                          `ConnectionType * new_connection()` to create new connections
     *                          `delete_connection(ConnectionType *)` to delete broken connections
     * @tparam ConnectionType - class representing connections of this TCP Server
     *                          tcp_server expects that ConnectionType provides function
     *                          `void run()` that will be called after establishing connection
     *                           with the client
     */
    template <class Impl, class ConnectionType>
    class tcp_server {
        typedef tcp_server<Impl, ConnectionType> this_type;
    public:
        /// constructor
        explicit tcp_server(io_service & ios)
            : m_ios(ios)
            , m_acceptor(ios) {
            static_assert(std::is_base_of<this_type, Impl>::value, "TCP Server implementation must be derived from tcp_server");
            tcp::acceptor::reuse_address reuse_address_option(true); error_code ignore_error;
            m_acceptor.set_option(reuse_address_option, ignore_error);
        }

        tcp_server(const tcp_server &) = delete;
        tcp_server & operator= (const tcp_server &) = delete;

        /// start accept connections
        void start(const tcp::endpoint bind_addr);

        /// start accept connections
        void start(uint16 port) {
            tcp::endpoint bind_addr(ip::address_v4::any(), port);
            start(bind_addr);
{'fraction_non_alphanumeric': 0.07690441533236293, 'fraction_numerical': 0.003396409509946628, 'mean_word_length': 2.272222222222222, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7557037', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1066, 'n_words': 315}