Ejemplo n.º 1
0
/* Collecting the correct servers */
static mcon_collection *filter_connections(mongo_con_manager *manager, int types, mongo_read_preference *rp)
{
	mcon_collection *col;
	mongo_con_manager_item *ptr = manager->connections;
	int current_pid, connection_pid;

	current_pid = getpid();
	col = mcon_init_collection(sizeof(mongo_connection*));

	mongo_manager_log(manager, MLOG_RS, MLOG_FINE, "filter_connections: adding connections:");
	while (ptr) {
		connection_pid = mongo_server_hash_to_pid(ptr->connection->hash);

		if (connection_pid != current_pid) {
			mongo_manager_log(manager, MLOG_RS, MLOG_FINE, "filter_connections: skipping %s as it doesn't match the current pid (%d)", ptr->connection->hash, current_pid);
		} else if (ptr->connection->connection_type & types) {
			mongo_print_connection_info(manager, ptr->connection, MLOG_FINE);
			mcon_collection_add(col, ptr->connection);
		}
		ptr = ptr->next;
	}
	mongo_manager_log(manager, MLOG_RS, MLOG_FINE, "filter_connections: done");

	return col;
}
Ejemplo n.º 2
0
void mongo_connection_destroy(mongo_con_manager *manager, mongo_connection *con)
{
	int current_pid, connection_pid;
	int i;

	current_pid = getpid();
	connection_pid = mongo_server_hash_to_pid(con->hash);

	/* Only close the connection if it matches the current PID */
	if (current_pid != connection_pid) {
		mongo_manager_log(manager, MLOG_CON, MLOG_INFO, "mongo_connection_destroy: The process pid (%d) for %s doesn't match the connection pid (%d).", current_pid, con->hash, connection_pid);
	} else {
		mongo_manager_log(manager, MLOG_CON, MLOG_FINE, "mongo_connection_destroy: Closing socket for %s.", con->hash);

#ifdef WIN32
		shutdown(con->socket, SD_BOTH);
		closesocket(con->socket);
		WSACleanup();
#else
		shutdown(con->socket, SHUT_RDWR);
		close(con->socket);
#endif
		for (i = 0; i < con->tag_count; i++) {
			free(con->tags[i]);
		}
		free(con->tags);
		free(con->hash);
		free(con);
	}
}
Ejemplo n.º 3
0
void mongo_connection_destroy(mongo_con_manager *manager, mongo_connection *con)
{
	int current_pid, connection_pid;
	int i;

	current_pid = getpid();
	connection_pid = mongo_server_hash_to_pid(con->hash);

	/* Only close the connection if it matches the current PID */
	if (current_pid != connection_pid) {
		mongo_manager_log(manager, MLOG_CON, MLOG_INFO, "mongo_connection_destroy: The process pid (%d) for %s doesn't match the connection pid (%d).", current_pid, con->hash, connection_pid);
	} else {
		mongo_manager_log(manager, MLOG_CON, MLOG_FINE, "mongo_connection_destroy: Closing socket for %s.", con->hash);

#ifdef WIN32
		shutdown(con->socket, SD_BOTH);
		closesocket(con->socket);
		WSACleanup();
#else
		shutdown(con->socket, SHUT_RDWR);
		close(con->socket);
#endif
		for (i = 0; i < con->tag_count; i++) {
			free(con->tags[i]);
		}
		if (con->cleanup_list) {
			mongo_connection_deregister_callback *ptr = con->cleanup_list;
			mongo_connection_deregister_callback *prev;
			do {
				if (ptr->callback_data) {
					ptr->mongo_cleanup_cb(ptr->callback_data);
				}

				if (!ptr->next) {
					free(ptr);
					ptr = NULL;
					break;
				}
				prev = ptr;
				ptr = ptr->next;
				free(prev);
				prev = NULL;
			} while(1);
			con->cleanup_list = NULL;
		}
		free(con->tags);
		free(con->hash);
		free(con);
	}
}
Ejemplo n.º 4
0
void mongo_connection_destroy(mongo_con_manager *manager, void *data, int why)
{
	int current_pid, connection_pid;
	int i;
	mongo_connection *con = (mongo_connection *)data;

	current_pid = getpid();
	connection_pid = mongo_server_hash_to_pid(con->hash);

	/* Only close the connection if it matches the current PID */
	if (current_pid == connection_pid) {
		mongo_manager_log(manager, MLOG_CON, MLOG_FINE, "mongo_connection_destroy: Destroying connection object for %s", con->hash);

		if (con->socket) {
			mongo_manager_log(manager, MLOG_CON, MLOG_FINE, "mongo_connection_destroy: Closing socket for %s.", con->hash);
			manager->close(con, why);
			con->socket = NULL;

			for (i = 0; i < con->tag_count; i++) {
				free(con->tags[i]);
			}
			free(con->tags);

			if (con->cleanup_list) {
				mongo_connection_deregister_callback *ptr = con->cleanup_list;
				mongo_connection_deregister_callback *prev;
				do {
					if (ptr->callback_data) {
						ptr->mongo_cleanup_cb(ptr->callback_data);
					}

					if (!ptr->next) {
						free(ptr);
						ptr = NULL;
						break;
					}
					prev = ptr;
					ptr = ptr->next;
					free(prev);
					prev = NULL;
				} while(1);
				con->cleanup_list = NULL;
			}
			free(con->hash);
			free(con);
		}
	} else {
		mongo_manager_log(manager, MLOG_CON, MLOG_INFO, "mongo_connection_destroy: The process pid (%d) for %s doesn't match the connection pid (%d).", current_pid, con->hash, connection_pid);
	}
}