Solved

Connection Management Structure in C language

Posted on 2006-10-31
3
235 Views
Last Modified: 2013-12-03
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?
0
Comment
Question by:rrahulgupta
  • 2
3 Comments
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
> 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
 

Author Comment

by:rrahulgupta
Comment Utility
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
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
Comment Utility
>> 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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now