<commit_before>"use strict";

// *********************************
// Libraries
// *********************************

var U               = require('util');
var Base            = require('./base');
var C               = require('./common').common();

var Dispatcher = exports.Dispatcher = function() {
    var obj      = Base.BaseObject();

    obj.dispatch = function( listener, conn ) {
        var state = this.state_object();

        // First, some bookkeeping; the listener got called,
        // so we're increasing it's stats
        listener.incr_stats();

        // Now, loop through all the remote servers we're supposed
        // to deliver this message to
        var i;
        for( i = 0; i < state.current_servers.length; i++ ) {
            var remote = state.current_servers[ i ];

            // Increment the remote stats, as we're using its connection
            remote.incr_stats();

            // There's 2 options; either both the listener & the remote
            // are streams, at which point we can pipe them, or they're
            // not, at which point we invoke it's 'send' method.

            // They're both streams, hooray; faster & easier
            if( listener.is_stream && remote.is_stream ) {
                C._trace( "Piping from "+ listener.type +" to "+ remote.name );

                // if the listener is a stream 'conn' is an actual connection
                conn.pipe( remote.connection, { end: false } );

            // If the listener is a stream, then the remote apparently
            // isn't one. So grab the data off the connection and send
            // it to the remote.
            } else if ( listener.is_stream ) {
                C._trace( "Manual send from "+ listener.type +" to "+ remote.name );

                conn.on( 'data', function (data) {

                    remote.send( data );
                    remote.last_send = C._now();
                });

            // The local listener isn't a stream, so 'conn' is not a<commit_msg>* use binding for "on data", add some commented out debug statements<commit_after>"use strict";

// *********************************
// Libraries
// *********************************

var U               = require('util');
var Base            = require('./base');
var C               = require('./common').common();

var Dispatcher = exports.Dispatcher = function() {
    var obj      = Base.BaseObject();

    obj.dispatch = function( listener, conn ) {
        var state = this.state_object();

        // First, some bookkeeping; the listener got called,
        // so we're increasing it's stats
        listener.incr_stats();

        //C._trace( ['In dispatch - State object:', state ] );

        // Now, loop through all the remote servers we're supposed
        // to deliver this message to
        var i;
        for( i = 0; i < state.current_servers.length; i++ ) {
            var remote = state.current_servers[ i ];

            //C._trace( ['In dispatch - Remote object:', remote ] );

            // Increment the remote stats, as we're using its connection
            remote.incr_stats();

            // There's 2 options; either both the listener & the remote
            // are streams, at which point we can pipe them, or they're
            // not, at which point we invoke it's 'send' method.

            // They're both streams, hooray; faster & easier
            if( listener.is_stream && remote.is_stream ) {
                C._trace( "Piping from "+ listener.type +" to "+ remote.name );

                // if the listener is a stream 'conn' is an actual connection
                conn.pipe( remote.connection, { end: false } );

            // If the listener is a stream, then the remote apparently
            // isn't one. So grab the data off the connection and send
            // it to the remote.
            } else if ( listener.is_stream ) {
                C._trace( "Manual send from "+ listener.type +" to "+ remote.name );

                conn.on( 'data', function (data) {

                    this.send( data );
                    this.last_send = C._now();
                }.bind(remote));

            // The local listener isn't a stream, so 'conn' is not a
{'fraction_non_alphanumeric': 0.14032181732134405, 'fraction_numerical': 0.000946521533364884, 'mean_word_length': 1.7609405617243632, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3779935', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1033, 'n_words': 399}