Solved

Connection Management Structure in C language

Posted on 2006-10-31
3
267 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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

756 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