2

Windows 7 SP1
MSVS 2010
MongoDB 2.2.0

骨格コード:

// Successful connection at the start.
mongo::DBClientConnection client_connection(true); // autoreconnect = true

// But (say) by the time we get here mongo has shut down.
try
{
    cursor = client_connection.query(...)
}
catch(const mongo::DBException& ex)
{
    cout << "DBException: " << ex.what() << "//" << ex.toString() << endl;
}

コンソールは最初に以下を出力します:

Thu Apr 25 14:03:09 Socket say send() errno:10054 An existing connection was forcibly closed by the remote host. 127.0.0.1:27017

次に、DBException がキャッチされます。

DBException: socket exception [SEND_ERROR] for 127.0.0.1:27017 9001 socket exception [2] server [127.0.0.1:27017]

再接続が試行されます:

Thu Apr 25 14:03:09 trying reconnect to localhost:27017
Thu Apr 25 14:03:10 reconnect localhost:27017 failed couldn't connect to server localhost:27017

そして私は得る:

ここに画像の説明を入力

私の質問:この再接続の失敗をキャッチして、正常に処理するにはどうすればよいですか?

4

0 に答える 0