Connection Management Structure in C language

I have to design and code the persistence(database) api to insert/update/delete the records in table in C language, there are number of tables in the database and so I want to create a common connection managenet entity so it will be reusable for across the api. To doing this should be my approach?
rrahulguptaAsked:
Who is Participating?
 
sunnycoderConnect With a Mentor Commented:
>> If yes, then connection would remain open until you explicitly close it.
>I say, yes. However, i would like to know that there some other option to do the same?
There are several ways to accomplish this kind of communcation but which one suits best depends on the application. Simplest possible solution would be to have server listen for incoming connections. Client connects, server accepts and services requests from the client - one at a time. After a client is finished, connection is closed and next client connection is accepted and served.

An obvious improvement to this would be to have a multi-threaded server capable of serving multiple clients. While this would make database more usable, it would also make it necessary to ensure proper synchronization between different threads.

Another variation would be to use UDP to post requests to server. This is usable if operations are idempotent and non-critical.

Yet another option is build a distributed computing environment with client using RPC calls to invoke service routines e.g. as used in CORBA.

>>This applies to server side too. you can use multiple threads in master/slave fashion where one thread assigns tasks
>>to other threads to process. Number of tables does not influence your connection.
>I didn't got that. can u plz explain it a bit more, please.

Client
1- Connect to server
2- Post request
3- parse response
4- If there are more requests, go to step 2
5- close connection

Server Main thread
1- Listen for client connections
2- Accept client connection
3- Spawn a worker thread and pass client socket to new worker thread to service this client
4- Go to step 1

Server worker thread
1- Accept client request
2- if client sought to close connection then close connection and exit
3- process client request
4- send response
5- Go to 1

There can again be several variations of this - e.g. master thread can maintain a pool of worker threads. Rather than spawning a thread for each request and letting it die after processing one client, same thread can be reused to serve other clients in future.

Yet another improvement would be to keep a pool of min and max threads and spawn/kill threads depending on server load as done in Apache web server.

lastly, the grading history in your profile might influence the kind of help you receive
Last 10 Grades Given B C
http://www.experts-exchange.com/help.jsp#hi73
0
 
sunnycoderCommented:
> I want to create a common connection managenet entity so it will be reusable for across the api.
You mean capability to access all table using a single connection? If yes, then connection would remain open until you explicitly close it. Keep passing the handle around and things would work fine. This applies to server side too. you can use multiple threads in master/slave fashion where one thread assigns tasks to other threads to process. Number of tables does not influence your connection.
0
 
rrahulguptaAuthor Commented:
Thanks sunny.
My questioned are inlined:

>You mean capability to access all table using a single connection?
Actually, i was thinking that this will be right approach if i can do it. but i was not sure because i don't have so much experience in C, however, i have pretty good idea about OOPs and java.

> If yes, then connection would remain open until you explicitly close it.
I say, yes. However, i would like to know that there some other option to do the same?  
 
>This applies to server side too. you can use multiple threads in master/slave fashion where one thread assigns tasks to other threads to process. Number of tables does not influence your connection.
I didn't got that. can u plz explain it a bit more, please.

0
All Courses

From novice to tech pro — start learning today.