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

From: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Maintaining connectivity/failing gracefully when my application is connected to a PostgreSQL server over Wi-fi on a PDT/PDA handset
Date: 2009-04-30 08:25:25
Message-ID: db471ace0904300125q53e0e12cq94629caedf72c83b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2009-04-30 08:54:08 Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking?
Previous Message Johan Nel 2009-04-30 07:12:47 Re: ERROR: syntax error at or near "IF"... why?