<commit_before>#include "vtrc-channels.h"
#include "vtrc-protocol-layer-s.h"

#include "vtrc-common/vtrc-call-context.h"
#include "vtrc-common/vtrc-exception.h"
#include "vtrc-common/vtrc-closure-holder.h"
#include "vtrc-common/vtrc-rpc-channel.h"

#include "protocol/vtrc-errors.pb.h"
#include "protocol/vtrc-rpc-lowlevel.pb.h"
#include "protocol/vtrc-rpc-options.pb.h"

//#include "vtrc-chrono.h"
#include "vtrc-bind.h"
#include "vtrc-ref.h"

namespace vtrc { namespace server {

    namespace {

        namespace gpb = google::protobuf;

        typedef vtrc_rpc::message_info message_info;

        const unsigned direct_call_type = message_info::MESSAGE_EVENT;
        const unsigned callback_type    = message_info::MESSAGE_CALLBACK;

        namespace gpb = google::protobuf;

        typedef vtrc_rpc::lowlevel_unit     lowlevel_unit_type;
        typedef vtrc::shared_ptr<lowlevel_unit_type> lowlevel_unit_sptr;

        class unicast_channel: public common::rpc_channel {

            common::connection_iface_wptr client_;
            const unsigned                message_type_;
            const bool                    disable_wait_;

        public:

            unicast_channel( common::connection_iface_sptr c,
                             unsigned mess_type, bool disable_wait)
                :common::rpc_channel(direct_call_type, callback_type)
                ,client_(c)
                ,message_type_(mess_type)
                ,disable_wait_(disable_wait)
            { }

            void send_message(lowlevel_unit_type &llu,
                        const google::protobuf::MethodDescriptor* method,
                              google::protobuf::RpcController*  /*controller*/,
                        const google::protobuf::Message*        /*request   */,
                              google::protobuf::Message*          response,
                              google::protobuf::Closure*          done )
            {
                common::closure_holder        clhl(done);
                common::connection_iface_sptr clk (client_.lock( ));

                if( clk.get( ) == NULL ) {
                    throw vtrc::common::exception( vtrc_errors::ERR_CHANNEL,
                                                   "Connection lost");
                }

                const vtrc_rpc::options &call_opt
                            ( get_protocol( *clk ).get_method_options(method) );

                configure_message( clk, message_type_, llu );

                const gpb::uint64 call_id = llu.id( );

                if( disable_wait_ ) {
                    llu.mutable_opt( )->set_wait(false);
                } else {
                    llu.mutable_opt( )->set_wait(call_opt.wait( ));
                    llu.mutable_opt( )
                        ->set_accept_callbacks(call_opt.accept_callbacks( ));
                }

                if( llu.opt( ).wait( ) ) { /// WAITABLE CALL

                    rpc_channel::context_holder ch( &get_protocol(*clk), &llu);
                    ch.ctx_->set_call_options( call_opt );
                    ch.ctx_->set_done_closure( done );

                    process_waitable_call( call_id, llu, response,
                                           clk, call_opt );

                } else {                  /// NOT WAITABLE CALL
                    get_protocol( *clk ).call_rpc_method( llu );
                }
            }
        };

        class broadcast_channel: public common::rpc_channel {

            typedef broadcast_channel               this_type;
            vtrc::weak_ptr<common::connection_list> clients_;
            common::connection_iface_wptr           sender_;
            const unsigned                          message_type_;
<commit_msg>proto<commit_after>#include "vtrc-channels.h"
#include "vtrc-protocol-layer-s.h"

#include "vtrc-common/vtrc-call-context.h"
#include "vtrc-common/vtrc-exception.h"
#include "vtrc-common/vtrc-closure-holder.h"
#include "vtrc-common/vtrc-rpc-channel.h"

#include "protocol/vtrc-errors.pb.h"
#include "protocol/vtrc-rpc-lowlevel.pb.h"
#include "protocol/vtrc-rpc-options.pb.h"

//#include "vtrc-chrono.h"
#include "vtrc-bind.h"
#include "vtrc-ref.h"

namespace vtrc { namespace server {

    namespace {

        namespace gpb = google::protobuf;

        typedef vtrc_rpc::message_info message_info;

        const unsigned direct_call_type = message_info::MESSAGE_EVENT;
        const unsigned callback_type    = message_info::MESSAGE_CALLBACK;

        namespace gpb = google::protobuf;

        typedef vtrc_rpc::lowlevel_unit     lowlevel_unit_type;
        typedef vtrc::shared_ptr<lowlevel_unit_type> lowlevel_unit_sptr;

        class unicast_channel: public common::rpc_channel {

            common::connection_iface_wptr client_;
            const unsigned                message_type_;
            const bool                    disable_wait_;

        public:

            unicast_channel( common::connection_iface_sptr c,
                             unsigned mess_type, bool disable_wait)
                :common::rpc_channel(direct_call_type, callback_type)
                ,client_(c)
                ,message_type_(mess_type)
                ,disable_wait_(disable_wait)
            { }

            void send_message(lowlevel_unit_type &llu,
                        const google::protobuf::MethodDescriptor* method,
                              google::protobuf::RpcController*  /*controller*/,
                        const google::protobuf::Message*        /*request   */,
                              google::protobuf::Message*          response,
                              google::protobuf::Closure*          done )
            {
                common::closure_holder        clhl(done);
                common::connection_iface_sptr clk (client_.lock( ));

                if( clk.get( ) == NULL ) {
                    throw vtrc::common::exception( vtrc_errors::ERR_CHANNEL,
                                                   "Connection lost");
                }

                const vtrc_rpc::options &call_opt
                            ( get_protocol( *clk ).get_method_options(method) );

                configure_message( clk, message_type_, llu );

                const gpb::uint64 call_id = llu.id( );

                if( disable_wait_ ) {
                    llu.mutable_opt( )->set_wait(false);
                } else {
                    llu.mutable_opt( )->set_wait(call_opt.wait( ));
                    llu.mutable_opt( )
                        ->set_accept_callbacks(call_opt.accept_callbacks( ));
                }

                if( llu.opt( ).wait( ) ) { /// WAITABLE CALL

                    rpc_channel::context_holder ch( &get_protocol(*clk), &llu);
                    ch.ctx_->set_call_options( call_opt );
                    ch.ctx_->set_done_closure( done );

                    process_waitable_call( call_id, llu, response,
                                           clk, call_opt );

                } else {                  /// NON WAITABLE CALL
                    get_protocol( *clk ).call_rpc_method( llu );
                }
            }
        };

        class broadcast_channel: public common::rpc_channel {

            typedef broadcast_channel               this_type;
            vtrc::weak_ptr<common::connection_list> clients_;
            common::connection_iface_wptr           sender_;
            const unsigned                          message_type_;

{'fraction_non_alphanumeric': 0.09583555792845702, 'fraction_numerical': 0.0005339028296849973, 'mean_word_length': 1.5634621963735889, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '494853', 'n_tokens_mistral': 2106, 'n_tokens_neox': 2000, 'n_words': 338}