/* API interface to fetch a connection */ mongo_connection *mongo_get_read_write_connection(mongo_con_manager *manager, mongo_servers *servers, int connection_flags, char **error_message) { /* In some cases we won't actually have a manager or servers initialized, for example when extending PHP objects without calling the constructor, * and then var_dump() it or access the properties, for example the "connected" property */ if (!manager || !servers) { return NULL; } /* Which connection we return depends on the type of connection we want */ switch (servers->options.con_type) { case MONGO_CON_TYPE_STANDALONE: mongo_manager_log(manager, MLOG_CON, MLOG_INFO, "mongo_get_read_write_connection: finding a STANDALONE connection"); return mongo_get_connection_multiple(manager, servers, connection_flags, error_message); case MONGO_CON_TYPE_REPLSET: mongo_manager_log( manager, MLOG_CON, MLOG_INFO, "mongo_get_read_write_connection: finding a REPLSET connection (%s)", connection_flags & MONGO_CON_FLAG_WRITE ? "write" : "read" ); return mongo_get_read_write_connection_replicaset(manager, servers, connection_flags, error_message); case MONGO_CON_TYPE_MULTIPLE: mongo_manager_log(manager, MLOG_CON, MLOG_INFO, "mongo_get_read_write_connection: finding a MULTIPLE connection"); return mongo_get_connection_multiple(manager, servers, connection_flags, error_message); default: mongo_manager_log(manager, MLOG_CON, MLOG_WARN, "mongo_get_read_write_connection: connection type %d is not supported", servers->options.con_type); *error_message = strdup("mongo_get_read_write_connection: Unknown connection type requested"); } return NULL; }
/* API interface to fetch a connection */ mongo_connection *mongo_get_read_write_connection(mongo_con_manager *manager, mongo_servers *servers, int connection_flags, char **error_message) { /* Which connection we return depends on the type of connection we want */ switch (servers->options.con_type) { case MONGO_CON_TYPE_STANDALONE: mongo_manager_log(manager, MLOG_CON, MLOG_INFO, "mongo_get_read_write_connection: finding a STANDALONE connection"); return mongo_get_connection_multiple(manager, servers, connection_flags, error_message); case MONGO_CON_TYPE_REPLSET: mongo_manager_log( manager, MLOG_CON, MLOG_INFO, "mongo_get_read_write_connection: finding a REPLSET connection (%s)", connection_flags & MONGO_CON_FLAG_WRITE ? "write" : "read" ); return mongo_get_read_write_connection_replicaset(manager, servers, connection_flags, error_message); case MONGO_CON_TYPE_MULTIPLE: mongo_manager_log(manager, MLOG_CON, MLOG_INFO, "mongo_get_read_write_connection: finding a MULTIPLE connection"); return mongo_get_connection_multiple(manager, servers, connection_flags, error_message); default: mongo_manager_log(manager, MLOG_CON, MLOG_WARN, "mongo_get_read_write_connection: connection type %d is not supported", servers->options.con_type); *error_message = strdup("mongo_get_read_write_connection: Unknown connection type requested"); } return NULL; }