mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-22 11:53:16 +00:00
handle connection lost
This commit is contained in:
parent
26dfea65e4
commit
15ece47601
@ -27,17 +27,26 @@ SWITCH_STANDARD_API(mongo_find_one_function)
|
|||||||
|
|
||||||
if (!zstr(ns) && !zstr(json_query) && !zstr(json_fields)) {
|
if (!zstr(ns) && !zstr(json_query) && !zstr(json_fields)) {
|
||||||
|
|
||||||
|
DBClientConnection *conn = NULL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BSONObj query = fromjson(json_query);
|
BSONObj query = fromjson(json_query);
|
||||||
BSONObj fields = fromjson(json_fields);
|
BSONObj fields = fromjson(json_fields);
|
||||||
|
|
||||||
DBClientConnection *conn = mongo_connection_pool_get(globals.conn_pool);
|
conn = mongo_connection_pool_get(globals.conn_pool);
|
||||||
BSONObj res = conn->findOne(ns, Query(query), &fields);
|
if (conn) {
|
||||||
mongo_connection_pool_put(globals.conn_pool, conn);
|
BSONObj res = conn->findOne(ns, Query(query), &fields);
|
||||||
|
mongo_connection_pool_put(globals.conn_pool, conn);
|
||||||
|
|
||||||
stream->write_function(stream, "-OK\n%s\n", res.toString().c_str());
|
stream->write_function(stream, "-OK\n%s\n", res.toString().c_str());
|
||||||
} catch (MsgAssertionException &e) {
|
} else {
|
||||||
stream->write_function(stream, "-ERR\n%s\n", e.what());
|
stream->write_function(stream, "-ERR\nNo connection\n");
|
||||||
|
}
|
||||||
|
} catch (DBException &e) {
|
||||||
|
if (conn) {
|
||||||
|
mongo_connection_destroy(&conn);
|
||||||
|
}
|
||||||
|
stream->write_function(stream, "-ERR\n%s\n", e.toString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@ typedef struct {
|
|||||||
} mongo_connection_pool_t;
|
} mongo_connection_pool_t;
|
||||||
|
|
||||||
|
|
||||||
|
switch_status_t mongo_connection_create(DBClientConnection **connection, const char *host);
|
||||||
|
void mongo_connection_destroy(DBClientConnection **conn);
|
||||||
|
|
||||||
switch_status_t mongo_connection_pool_create(mongo_connection_pool_t **conn_pool, switch_size_t min_connections, switch_size_t max_connections,
|
switch_status_t mongo_connection_pool_create(mongo_connection_pool_t **conn_pool, switch_size_t min_connections, switch_size_t max_connections,
|
||||||
const char *host);
|
const char *host);
|
||||||
void mongo_connection_pool_destroy(mongo_connection_pool_t **conn_pool);
|
void mongo_connection_pool_destroy(mongo_connection_pool_t **conn_pool);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user