<commit_before>/*
 * (c) 2005-2018  Copyright, Real-Time Innovations, Inc. All rights reserved.
 * Subject to Eclipse Public License v1.0; see LICENSE.md for details.
 */


#include "RTIRawTransportImpl.h"

#if defined(RTI_WIN32) || defined(RTI_INTIME)
#pragma warning(push)
#pragma warning(disable : 4996)
#endif

std::vector<NDDS_Transport_SendResource_t> PeerData::resourcesList;
unsigned int RTIRawTransportImpl::pubWorkerCount = 0;
unsigned int RTIRawTransportImpl::subWorkerCount = 0;
/*********************************************************
 * Constructor
 */
RTIRawTransportImpl::RTIRawTransportImpl()
        : _transport(),
          _pongSemaphore(NULL),
          _plugin(NULL),
          _workerFactory(NULL),
          _exclusiveArea(NULL),
          _PM(NULL)
{
    PeerData::resourcesList.reserve(RTIPERFTEST_MAX_PEERS);

    if (!get_serialized_overhead_size(perftest_cpp::OVERHEAD_BYTES)) {
        throw std::runtime_error("[Error] RTIRawTransportImpl: "
                "get_serialized_overhead_size returned error");
    }
}

/*********************************************************
 * Shutdown
 */
void RTIRawTransportImpl::Shutdown()
{

    for (unsigned int i = 0; i < PeerData::resourcesList.size(); i++) {
        if (PeerData::resourcesList[i] != NULL && _plugin != NULL) {
            _plugin->destroy_sendresource_srEA(
                    _plugin, _peersDataList[i].resource);
            PeerData::resourcesList[i] = NULL;
        }
    }

    if (_plugin != NULL) {
        _plugin->delete_cEA(_plugin, NULL);
    }
    if (_exclusiveArea != NULL){
        REDAWorkerFactory_destroyExclusiveArea(_workerFactory, _exclusiveArea);
    }
    if (_workerFactory != NULL) {
        REDAWorkerFactory_delete(_workerFactory);
    }
    if (_pongSemaphore != NULL) {
        RTIOsapiSemaphore_delete(_pongSemaphore);
        _pongSemaphore = NULL;
    }

}

/*********************************************************
 * validate_input
 */
bool RTIRawTransportImpl::validate_input() {

    // Manage parameter -batchSize
    if (_PM->get<long>("batchSize") > 0) {
        // We will not use batching for a latency test
        if (_PM->get<bool>("latencyTest")) {
            if (_PM->is_set("batchSize")) {
                fprintf(stderr, "Batching cannot be used in a Latency test.\n");
                return false;
            } else {
                _PM->set<long>("batchSize", 0); // Disable Batching
            }
        }
    }

    if (((unsigned long) _PM->get<long>("batchSize")
                < _PM->get<unsigned long long>("dataLen") * 2)
            && !_PM->is_set("scan")) {
        /*
         * We don't want to use batching if the batch size is not large
         * enough to contain at least two samples (in this case we avoid the
         * checking at the middleware level).<commit_msg>Disable batching by default in Raw Transport<commit_after>/*
 * (c) 2005-2018  Copyright, Real-Time Innovations, Inc. All rights reserved.
 * Subject to Eclipse Public License v1.0; see LICENSE.md for details.
 */


#include "RTIRawTransportImpl.h"

#if defined(RTI_WIN32) || defined(RTI_INTIME)
#pragma warning(push)
#pragma warning(disable : 4996)
#endif

std::vector<NDDS_Transport_SendResource_t> PeerData::resourcesList;
unsigned int RTIRawTransportImpl::pubWorkerCount = 0;
unsigned int RTIRawTransportImpl::subWorkerCount = 0;
/*********************************************************
 * Constructor
 */
RTIRawTransportImpl::RTIRawTransportImpl()
        : _transport(),
          _pongSemaphore(NULL),
          _plugin(NULL),
          _workerFactory(NULL),
          _exclusiveArea(NULL),
          _PM(NULL)
{
    PeerData::resourcesList.reserve(RTIPERFTEST_MAX_PEERS);

    if (!get_serialized_overhead_size(perftest_cpp::OVERHEAD_BYTES)) {
        throw std::runtime_error("[Error] RTIRawTransportImpl: "
                "get_serialized_overhead_size returned error");
    }
}

/*********************************************************
 * Shutdown
 */
void RTIRawTransportImpl::Shutdown()
{

    for (unsigned int i = 0; i < PeerData::resourcesList.size(); i++) {
        if (PeerData::resourcesList[i] != NULL && _plugin != NULL) {
            _plugin->destroy_sendresource_srEA(
                    _plugin, _peersDataList[i].resource);
            PeerData::resourcesList[i] = NULL;
        }
    }

    if (_plugin != NULL) {
        _plugin->delete_cEA(_plugin, NULL);
    }
    if (_exclusiveArea != NULL){
        REDAWorkerFactory_destroyExclusiveArea(_workerFactory, _exclusiveArea);
    }
    if (_workerFactory != NULL) {
        REDAWorkerFactory_delete(_workerFactory);
    }
    if (_pongSemaphore != NULL) {
        RTIOsapiSemaphore_delete(_pongSemaphore);
        _pongSemaphore = NULL;
    }

}

/*********************************************************
 * validate_input
 */
bool RTIRawTransportImpl::validate_input() {

    // Manage parameter -batchSize

    /*
     * If the parameter is not set by default, even for throughput we will set
     * it to 0. We allow the use of batching, to be able to compare, but this is
     * not a feature that "sockets" have, therefore we should not use them by
     * default
     */

    if (_PM->get<long>("batchSize") > 0) {
        // If it was not explicit:
        if (!_PM->is_set("batchSize")) {
            _PM->set<long>("batchSize", 0); // Disable Batching
        } else { // If it was explicit, it is ok as long as it is not a lat test
            if (_PM->get<bool>("latencyTest")) {
                fprintf(stderr, "Batching cannot be used in a Latency test.\n");
                return false;
            }
        }
    }

    if (((unsigned long) _PM->get<long>("batchSize")
                < _PM->get<unsigned long long>("dataLen") * 2)
            && !_PM->is_set("scan")) {
        /*
         * We don't want to use batching if the batch size is not large
         * enough to contain at least two samples (in this case we avoid the
         * checking at the middleware level).
{'fraction_non_alphanumeric': 0.1669437978051214, 'fraction_numerical': 0.007482540738277353, 'mean_word_length': 2.883150419625565, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, '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': '3721139', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1742, 'n_words': 418}