Esempio n. 1
0
File: pq.cpp Progetto: adfin/mordor
void fillUsers(Connection &conn)
{
    conn.execute("CREATE TEMPORARY TABLE users (id INTEGER, name TEXT, height SMALLINT, awesome BOOLEAN, company TEXT, gender CHAR, efficiency REAL, crazy DOUBLE PRECISION, sometime TIMESTAMP)");
    conn.execute("INSERT INTO users VALUES (1, 'cody', 72, true, 'Mozy', 'M', .9, .75, '2009-05-19 15:53:45.123456')");
    conn.execute("INSERT INTO users VALUES (2, 'brian', 70, false, NULL, 'M', .9, .25, NULL)");
}
void MultiplexedConnections::sendQuery(
	const String & query,
	const String & query_id,
	UInt64 stage,
	const ClientInfo * client_info,
	bool with_pending_data)
{
	std::lock_guard<std::mutex> lock(cancel_mutex);

	if (sent_query)
		throw Exception("Query already sent.", ErrorCodes::LOGICAL_ERROR);

	if (supports_parallel_execution)
	{
		if (settings == nullptr)
		{
			/// Каждый шард имеет один адрес.
			auto it = connections.begin();
			for (size_t i = 0; i < shard_states.size(); ++i)
			{
				Connection * connection = *it;
				if (connection == nullptr)
					throw Exception("MultiplexedConnections: Internal error", ErrorCodes::LOGICAL_ERROR);

				connection->sendQuery(query, query_id, stage, nullptr, client_info, with_pending_data);
				++it;
			}
		}
		else
		{
			/// Каждый шард имеет одну или несколько реплик.
			auto it = connections.begin();
			for (const auto & shard_state : shard_states)
			{
				Settings query_settings = *settings;
				query_settings.parallel_replicas_count = shard_state.active_connection_count;

				UInt64 offset = 0;

				for (size_t i = 0; i < shard_state.allocated_connection_count; ++i)
				{
					Connection * connection = *it;
					if (connection == nullptr)
						throw Exception("MultiplexedConnections: Internal error", ErrorCodes::LOGICAL_ERROR);

					query_settings.parallel_replica_offset = offset;
					connection->sendQuery(query, query_id, stage, &query_settings, client_info, with_pending_data);
					++offset;
					++it;
				}
			}
		}
	}
	else
	{
		Connection * connection = connections[0];
		if (connection == nullptr)
			throw Exception("MultiplexedConnections: Internal error", ErrorCodes::LOGICAL_ERROR);

		connection->sendQuery(query, query_id, stage, settings, client_info, with_pending_data);
	}

	sent_query = true;
}
Esempio n. 3
0
 ~SceneInfo(){
     sigDetachedFromRootConnection.disconnect();
     sigCheckToggledConnection.disconnect();
 }
#include <measurement_kit/common.hpp>

#include <measurement_kit/net.hpp>

#include "src/net/connection.hpp"

using namespace mk;
using namespace mk::net;

TEST_CASE("Ensure that the constructor socket-validity checks work") {

    SECTION("Invalid values are properly normalized") {
        {
            /* Common for both Unix and Windows */
            Connection conn(-1);
            REQUIRE(conn.get_fileno() == -1);
        }
#ifndef WIN32
        {
            Connection conn(-2);
            REQUIRE(conn.get_fileno() == -1);
        }
        /* ... */
        {
            Connection conn(INT_MIN);
            REQUIRE(conn.get_fileno() == -1);
        }
#endif
    }
Esempio n. 5
0
void ConnectionManager::addWaiting(Connection& conn) {
	std::cout << conn.getAddr_p() << " add to wait" << std::endl;
	waitting_conn.push_back(conn);
}
Esempio n. 6
0
bool Connection::closed() const
{
  Connection *self = const_cast<Connection *>(this);
  return !self->socket().is_open();
}