Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Connection Management Structure in C language

Posted on 2006-10-31
3
Medium Priority
?
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17847777
> 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
ID: 17849071
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 2000 total points
ID: 17855625
>> 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

671 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