Maintaining connectivity/failing gracefully when my application is connected to a PostgreSQL server over Wi-fi on a PDT/PDA handset

Поиск
Список
Период
Сортировка
От Peter Geoghegan
Тема Maintaining connectivity/failing gracefully when my application is connected to a PostgreSQL server over Wi-fi on a PDT/PDA handset
Дата
Msg-id db471ace0904300125q53e0e12cq94629caedf72c83b@mail.gmail.com
обсуждение исходный текст
Список pgsql-general
Hello,

I'm developing a PostgreSQL application for Windows CE 5 on a PDT/ PDA
in C++/Qt, using Hiroshi Saito's libpq port for that platform. Since
the connection is established over wi-fi, and wi-fi connectivity is
often flaky, I feel that I have to "fail gracefully" to as great an
extent as possible. The following utility function,
VerifyDbConnection(), is called before every piece of database work:

void MainInterface::VerifyDbConnection()
{
   if (PQstatus(conn) != CONNECTION_OK)
   {
               for(;;)
               {
                       PQreset(conn);
                       if(PQstatus(conn) == CONNECTION_OK)
                               return;

                       QMessageBox msgbox_connection_lost;
                       msgbox_connection_lost.setText("Connection to
the database is lost, and cannot be re-established. "
                               "This may be due to the fact that
you're too far away from the Wi-fi access point, or because "
                               "the backoffice computer is turned off,
or it may be a low level connectivity problem." );
                       QPushButton* retry_button =
msgbox_connection_lost.addButton(tr("Reconnect"),
QMessageBox::ActionRole);
                       QPushButton* exit_button =
msgbox_connection_lost.addButton(tr("Exit"), QMessageBox::ActionRole);
                       msgbox_connection_lost.setWindowTitle("Connection lost");
                       msgbox_connection_lost.exec();

                       if(msgbox_connection_lost.clickedButton() ==
retry_button)
                       {
                               continue;
                       }
                       else if(msgbox_connection_lost.clickedButton()
== exit_button)
                       {
                               exit(0);
                               return;
                       }
               }
   }

}

This seemed to work fine initially; I'd abruptly stop the database
server, and I would see a messagebox informing me of a connectivity
problem. Then, I'd start the server, click the retry button, and have
connectivity restored. However, when I walk out of range of the wi-fi
access point, which is the probable cause of losing connectivity in
the real world, my program crashes without displaying an error message
(I would expect to see a visual C++ runtime error message).

Can someone suggest a reason for this, or a workaround?

Regards,
Peter Geoghegan

В списке pgsql-general по дате отправления:

Предыдущее
От: Henry
Дата:
Сообщение: PANIC: right sibling's left-link doesn't match
Следующее
От: Grzegorz Buś
Дата:
Сообщение: could not bind IPv4 socket