]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
handle connection lost
authorTamas Cseke <cstomi@eworldcom.hu>
Thu, 12 May 2011 08:29:55 +0000 (10:29 +0200)
committerTamas Cseke <cstomi@eworldcom.hu>
Thu, 12 May 2011 08:29:55 +0000 (10:29 +0200)
src/mod/applications/mod_mongo/mod_mongo.cpp
src/mod/applications/mod_mongo/mod_mongo.h

index d76e8857651a53e04467958122d28d9e47a6e5eb..bb82c840e031d601acf96b2d463691e0852b14ed 100644 (file)
@@ -27,17 +27,26 @@ SWITCH_STANDARD_API(mongo_find_one_function)
 
   if (!zstr(ns) && !zstr(json_query) && !zstr(json_fields)) {
 
+         DBClientConnection *conn = NULL;
+
          try {
                  BSONObj query = fromjson(json_query);
                  BSONObj fields = fromjson(json_fields);
 
-                 DBClientConnection *conn = mongo_connection_pool_get(globals.conn_pool);        
-                 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());
-         } catch (MsgAssertionException &e) {
-                 stream->write_function(stream, "-ERR\n%s\n", e.what());
+                 conn = mongo_connection_pool_get(globals.conn_pool);
+                 if (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());
+                 } else {
+                         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());
          }
 
 
index 5d2ed54dcb45f32a30f666be3341e6fa65cc2dd7..91c14bb29b4a1e227a43d7755d2357250a71933e 100644 (file)
@@ -22,6 +22,9 @@ typedef struct {
 } 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,
                                             const char *host);
 void mongo_connection_pool_destroy(mongo_connection_pool_t **conn_pool);