Article View: borland.public.cppbuilder.internet.socket
Article #3034TIdTCPServer, services, and DB Backup
From: Vladimir Stefanovic
Date: Fri, 25 Nov 2005 09:08
Date: Fri, 25 Nov 2005 09:08
63 lines
2551 bytes
2551 bytes
Hi,
I want to make a DB backup while both the service
application and server socket are active. Server
socket adds data to the DB, so I must somehow
allow pending connections to finish and stop new
connections to affect the DB. But I still want to
inform the clients what's going on (backup).
This is how I imagined the scenario. Can you please
tell me if the presented concept is acceptable?
// PSEUDO
void __fastcall TTicketService::IdTCPServerExecute(TIdPeerThread *AThread)
{
// SERVER RECEIVES REQUEST FROM CLIENT ...
AThread->Connection->Read...( READ REQUEST FROM CLIENT );
// IF IT'S TIME FOR DB BACKUP ...
if ( TimeForBackup )
{
// SERVER SENDS RESPONSE TO CLIENT ...
AThread->Connection->Write...( NOT DONE, BECAUSE OF ... PLEASE TRY AGAIN LATER );
}
else
{
// counter of connections which *accesses* DB
RAII_CritSec_Increment_Decrement(); // in constructor ++counter, in destructor --counter
// BLOCK OF CODE IN WHICH DB IS ACCESSED...
DB->Table->CritSec_Add...( DATA RECEIVED FROM CLIENT );
// SERVER SENDS RESPONSE TO CLIENT ...
AThread->Connection->Write...( DATA WAS SUCCESFULY STORED! );
}
}
// PSEUDO
void __fastcall TTicketService::ServiceExecute(TService *Sender)
{
while ( !Terminated )
{
if ( ( TimeForBackup ) && ( counter == 0 ) )
{
BACKUP_DB();
TimeForBackup = false;
}
Sleep ( 500 );
ServiceThread->ProcessRequests( false );
}
}
Best Regards,
Vladimir Stefanovic
Technical Details
Message-ID:
<4386e2bb$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,fb1ab29895c49753,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu> Sender: "Vladimir Stefanovic" <antivari@po.sbb.co.yu> Reply-To: "Vladimir Stefanovic" <antivari@po.sbb.co.yu> Subject: TIdTCPServer, services, and DB Backup Newsgroups: borland.public.cppbuilder.internet.socket X-User-Info: 213.137.116.223 X-Forwarded-For: 128.128.129.165 NNTP-Posting-Host: 207.105.83.66 Message-ID: <4386e2bb$1@newsgroups.borland.com> Date: 25 Nov 2005 02:08:59 -0700 X-Trace: newsgroups.borland.com 1132913339 207.105.83.66 (25 Nov 2005 02:08:59 -0700) Lines: 63 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail