예제 #1
0
void Connection::closeConnection()
{
	//dispatcher thread
	#ifdef __DEBUG_NET_DETAIL__
	std::clog << "Connection::closeConnection" << std::endl;
	#endif
	m_connectionLock.lock();
	if(m_connectionState != CONNECTION_STATE_REQUEST_CLOSE)
	{
		std::clog << "[Error - Connection::closeConnection] m_connectionState = " << m_connectionState << std::endl;
		m_connectionLock.unlock();
		return;
	}

	if(m_protocol)
	{
		m_protocol->setConnection(Connection_ptr());
		m_protocol->releaseProtocol();
		m_protocol = NULL;
	}

	m_connectionState = CONNECTION_STATE_CLOSING;
	if(!m_pendingWrite || m_writeError)
	{
		closeSocket();
		releaseConnection();
		m_connectionState = CONNECTION_STATE_CLOSED;
	}

	m_connectionLock.unlock();
}
예제 #2
0
void Connection::closeConnectionTask()
{
	//dispatcher thread
	#ifdef __DEBUG_NET_DETAIL__
	std::cout << "Connection::closeConnectionTask" << std::endl;
	#endif

	m_connectionLock.lock();
	if(m_connectionState != CONNECTION_STATE_REQUEST_CLOSE){
		std::cout << "Error: [Connection::closeConnectionTask] m_connectionState = " << m_connectionState << std::endl;
		m_connectionLock.unlock();
		return;
	}

	if(m_protocol){
		m_protocol->setConnection(Connection_ptr());
		m_protocol->releaseProtocol();
		m_protocol = NULL;
	}

	m_connectionState = CONNECTION_STATE_CLOSING;

	if(m_pendingWrite == 0 || m_writeError){
		closeSocket();
		releaseConnection();
		m_connectionState = CONNECTION_STATE_CLOSED;
	}
	else{
		//will be closed by onWriteOperation/handleWriteTimeout/handleReadTimeout instead
	}

	m_connectionLock.unlock();
}
예제 #3
0
void Connection::closeConnection() {
	LOGt("Connection::closeConnection()");

	boost::recursive_mutex::scoped_lock lock(m_connectionLock);

	if(m_connectionState != CONNECTION_STATE_REQUEST_CLOSE)
	{
		LOGe("[Connection::closeConnection] m_connectionState = " << m_connectionState);
		return;
	}

	if(m_protocol)
	{
		m_protocol->setConnection(Connection_ptr());
		m_protocol->releaseProtocol();
		m_protocol = nullptr;
	}

	m_connectionState = CONNECTION_STATE_CLOSING;
	if(!m_pendingWrite || m_writeError)
	{
		closeSocket();
		releaseConnection();
		m_connectionState = CONNECTION_STATE_CLOSED;
	}
}
예제 #4
0
void Connection::closeConnectionTask()
{
	//dispatcher thread
	std::lock_guard<std::recursive_mutex> lockClass(m_connectionLock);

	if (m_connectionState != CONNECTION_STATE_REQUEST_CLOSE) {
		std::cout << "Error: [Connection::closeConnectionTask] m_connectionState = " << m_connectionState << std::endl;
		return;
	}

	if (m_protocol) {
		m_protocol->setConnection(Connection_ptr());
		m_protocol->releaseProtocol();
		m_protocol = nullptr;
	}

	m_connectionState = CONNECTION_STATE_CLOSING;

	if (m_pendingWrite == 0 || m_writeError) {
		closeSocket();
		releaseConnection();
		m_connectionState = CONNECTION_STATE_CLOSED;
	} else {
		//will be closed by onWriteOperation/handleWriteTimeout/handleReadTimeout instead
	}
}
예제 #5
0
/** handles client connections */
void ServerModule::manageClients()
{
	ClientModule * client;
	// queue broadcast data to send to clients
	if(m_broadcastData.size() > 0)
	{
		for(int i = 0; i < m_clients->size(); ++i)
		{
			client = (ClientModule*)m_clients->get(i);
			if(client)
			{
				client->getOutbox()->add(&m_broadcastData);
			}
		}
		m_broadcastData.reset();
		if(m_state == LISTENING)
		{
			m_state = SENDING_DATA;
		}
	}
	// handle logic for all clients
	for(int i = 0; i < m_clients->size(); ++i)
	{
		client = (ClientModule*)m_clients->get(i);
		if(client)
		{
			if(client->getState() == NET_ERROR)
			{
				releaseConnection(i);
				if(m_state == LISTENING)
				{
					m_state = PROCESSING;
				}
			}
			else
			{
				int oldState = client->getState();
				client->run();
				if(client->getState() != oldState && m_state == LISTENING)
				{
					m_state = PROCESSING;
				}
				ByteBuffer * inbox = client->getInbox();
				// broadcast everything the server hears from the clients.
				if(inbox->size() > 0)
				{
					m_broadcastData.add(inbox);
					if(m_state == LISTENING)
					{
						m_state = READING_DATA;
					}
					// don't bother keeping track of everything the clients have recieved... these are dummy modules
					inbox->reset();
				}
			}
		}
	}
}
예제 #6
0
void
OutputPlugin::connect(const std::string &topic)
{
	try {
		current_connection = getConnection();
		if(session == NULL) {
			session = current_connection->createSession(/* TODO: ackMode */);
			destination = session->createTopic(topic);
			producer = session->createProducer(destination);
		}
		current_connection->start();
		releaseConnection();
	} catch (cms::CMSException &e) {
		glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG, "OutputPlugin::connect exception: %s", e.what());
		releaseConnection();
		cleanup();
		throw e;
	}
}
예제 #7
0
/** frees all client sockets and shuts down the listening socket */
void ServerModule::release()
{
	if(m_clients)
	{
		for(int i = 0; i < m_clients->size(); ++i)
		{
			if(m_clients->get(i))
				releaseConnection(i);
		}
		delete m_clients;
		m_clients = 0;
	}
	releaseSockets();
}
예제 #8
0
	bool Database::execute( const std::string& statement )
	{
		sql::Connection* con = NULL;
		try
		{
			con = getConnection();
			std::auto_ptr<sql::Statement> stmt(con->createStatement());
			stmt->execute(statement);
			if(con)
			{
				releaseConnection(con);
				con = NULL;
			}
		}
		catch(sql::SQLException &e){
			if(con)
			{
				releaseConnection(con);
				con = NULL;
			}
			return false;
		}
		return true;
	}