Thread View: borland.public.cppbuilder.internet.socket
1 messages
1 total messages
Started by Vladimir Stefanovic
Fri, 25 Nov 2005 09:08
TIdTCPServer, services, and DB Backup
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads