<commit_before>/* Copyright (c) 2010 Stanford University
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "TransportManager.h"
#include "TransportFactory.h"

#include "TCPTransport.h"
#include "FastTransport.h"
#include "UdpDriver.h"

namespace RAMCloud {

static struct TcpTransportFactory : public TransportFactory {
    TcpTransportFactory()
        : TransportFactory("kernelTcp", "tcp") {}
    Transport* createTransport(const ServiceLocator* localServiceLocator) {
        return new TCPTransport(localServiceLocator);
    }
} tcpTransportFactory;

static struct FastUdpTransportFactory : public TransportFactory {
    FastUdpTransportFactory()
        : TransportFactory("fast+kernelUdp", "fast+udp") {}
    Transport* createTransport(const ServiceLocator* localServiceLocator) {
        return new FastTransport(new UdpDriver(localServiceLocator));
    }
} fastUdpTransportFactory;


/**
 * The single instance of #TransportManager.
 */
TransportManager transportManager;

TransportManager::TransportManager()
    : initialized(false)
    , transportFactories()
    , listening()
    , nextToListen(0)
    , transports()
{
    transportFactories.insert(&tcpTransportFactory);
    transportFactories.insert(&fastUdpTransportFactory);
}

TransportManager::~TransportManager()
{
    std::set<Transport*> toFree;
    BOOST_FOREACH(Transports::value_type protocolTransport, transports) {
        toFree.insert(protocolTransport.second);
    }
    BOOST_FOREACH(Transport* transport, toFree) {
        delete transport;
    }

}

/**
 * Construct the individual transports that will be used to send and receive.
 *
 * Calling this method is required before any calls to #serverRecv(), since the
 * receiving transports need to be instantiated with their local addresses
 * first. In this case, it must be called explicitly before any calls to
 * #getSession().<commit_msg>Add infiniband.<commit_after>/* Copyright (c) 2010 Stanford University
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "TransportManager.h"
#include "TransportFactory.h"

#include "TCPTransport.h"
#include "FastTransport.h"
#include "InfRCTransport.h"
#include "UdpDriver.h"

namespace RAMCloud {

static struct TcpTransportFactory : public TransportFactory {
    TcpTransportFactory()
        : TransportFactory("kernelTcp", "tcp") {}
    Transport* createTransport(const ServiceLocator* localServiceLocator) {
        return new TCPTransport(localServiceLocator);
    }
} tcpTransportFactory;

static struct FastUdpTransportFactory : public TransportFactory {
    FastUdpTransportFactory()
        : TransportFactory("fast+kernelUdp", "fast+udp") {}
    Transport* createTransport(const ServiceLocator* localServiceLocator) {
        return new FastTransport(new UdpDriver(localServiceLocator));
    }
} fastUdpTransportFactory;

static struct InfRCTransportFactory : public TransportFactory {
    InfRCTransportFactory()
        : TransportFactory("infinibandrc", "infrc") {}
    Transport* createTransport(const ServiceLocator* localServiceLocator) {
        return new InfRCTransport(localServiceLocator);
    }
} infRCTransportFactory;


/**
 * The single instance of #TransportManager.
 */
TransportManager transportManager;

TransportManager::TransportManager()
    : initialized(false)
    , transportFactories()
    , listening()
    , nextToListen(0)
    , transports()
{
    transportFactories.insert(&tcpTransportFactory);
    transportFactories.insert(&fastUdpTransportFactory);
    transportFactories.insert(&infRCTransportFactory);
}

TransportManager::~TransportManager()
{
    std::set<Transport*> toFree;
    BOOST_FOREACH(Transports::value_type protocolTransport, transports) {
        toFree.insert(protocolTransport.second);
    }
    BOOST_FOREACH(Transport* transport, toFree) {
        delete transport;
    }

}

/**
 * Construct the individual transports that will be used to send and receive.
 *
 * Calling this method is required before any calls to #serverRecv(), since the
 * receiving transports need to be instantiated with their local addresses
 * first. In this case, it must be called explicitly before any calls to
 * #getSession().
{'fraction_non_alphanumeric': 0.08083182640144665, 'fraction_numerical': 0.0018083182640144665, 'mean_word_length': 4.632382892057026, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5796349', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1416, 'n_words': 491}