473,770 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Designing a proper server model

Hello,

I'm currently in the process of implementing a web server. I've
currently applied the Reactor pattern an Half Sync/Half Async pattern
for accepting client connections and creating a thread pool.

Now, I'm using the select() mechanism to determine which sockets are
ready to be read/written to. When an activity occurs, all the 'active'
socket handles are sent to a queue. These are picked up by a thread of a
thread pool.

Now, basically, this thread now has a socket file descriptor it can read
from. However, nothing guarantees that this is going to be either the
first or the last time it's read from (as in, not the complete message
might be passed on in one go).

What is The Right Way of solving this problem ? What is a good mechanism
to be able to read from a socket multiple times from multiple threads,
but still have all the data, in the right order, accessible so it can be
parsed when everything is received ?

The only solution I can think of now is to give each thread a pointer to
a general 'data queue' class. This class will separate all incoming
data, based on the handle, and should use mutual exclusions to prevent
race conditions.

I do have the feeling this isn't the correct way to do this. Anyone
knows of any better solution ?

Thanks in advance for any ideas.

Regards,

Leon Mergencomp.lang .c++

Jul 23 '05 #1
5 1181
"Leon Mergen" <lm*****@gmail. com> wrote...
I'm currently in the process of implementing a web server. [...]

Now, I'm using the select() mechanism [...]

Now, basically, this thread [...]

What is The Right Way of solving this problem ?
Neigher 'select()' nor threading is topical here.
The only solution I can think of now is to give each thread a pointer to
a general 'data queue' class. This class will separate all incoming
data, based on the handle, and should use mutual exclusions to prevent
race conditions.
Race conditions are not topical here either.
I do have the feeling this isn't the correct way to do this. Anyone
knows of any better solution ?


Somebody in a newsgroup dedicated to your OS probably does. Your
question has nothing to do with C++ language.

V
Jul 23 '05 #2
On Sun, 2005-02-20 at 13:25 -0500, Victor Bazarov wrote:
I do have the feeling this isn't the correct way to do this. Anyone
knows of any better solution ?


Somebody in a newsgroup dedicated to your OS probably does. Your
question has nothing to do with C++ language.


I'm sorry, but exactly how is this OS specific ? The only thing I said
that's OS related was that I'm using the select() call... this is mainly
to illustrate how the reactor works.

Now, this problem is simply what the best solution is to combine the
slices of data received from multiple socket in multiple threads. I
don't see how this is OS-specific.

I see questions here about how to use the if() statement; no offense,
but I think to the average C++ software engineer, this is a far more
interesting question.

Anyway, thanks for your reply and your attempt to help me.

Leon Mergen

Jul 23 '05 #3
"Leon Mergen" <lm*****@gmail. com> wrote...
On Sun, 2005-02-20 at 13:25 -0500, Victor Bazarov wrote:
> I do have the feeling this isn't the correct way to do this. Anyone
> knows of any better solution ?
Somebody in a newsgroup dedicated to your OS probably does. Your
question has nothing to do with C++ language.


I'm sorry, but exactly how is this OS specific ? The only thing I said
that's OS related was that I'm using the select() call... this is mainly
to illustrate how the reactor works.


You mentioned threads, and I understood it to be your main concern.
C++ has no support for threads. Try comp.programmin g.threads in
addition to the newsgroup for your OS.
Now, this problem is simply what the best solution is to combine the
slices of data received from multiple socket in multiple threads. I
don't see how this is OS-specific.
Threads do not exist in C++ language. They exist in the OS execution
environment. That's why a newsgroup for the OS is infinitely better
for questions about threads than comp.lang.c++.
I see questions here about how to use the if() statement; no offense,
but I think to the average C++ software engineer, this is a far more
interesting question.


There are plenty of interesting things in the world that are totally
off-topic here.

I hope I answered your questions regarding the topicality (or lack
thereof) in your post.

V
Jul 23 '05 #4
On Sun, 2005-02-20 at 14:44 -0500, Victor Bazarov wrote:
Now, this problem is simply what the best solution is to combine the
slices of data received from multiple socket in multiple threads. I
don't see how this is OS-specific.


Threads do not exist in C++ language. They exist in the OS execution
environment. That's why a newsgroup for the OS is infinitely better
for questions about threads than comp.lang.c++.


Ok, I had no idea there was no support for asynchronous execution in c++
by default. I understand the irrelevance, and will continue the
discussion in comp.programmin g.threads .

Regards,

Leon Mergen

Jul 23 '05 #5
On Sun, 20 Feb 2005 20:34:53 +0100, Leon Mergen
<lm*****@gmail. com> wrote:
On Sun, 2005-02-20 at 13:25 -0500, Victor Bazarov wrote:
> I do have the feeling this isn't the correct way to do this. Anyone
> knows of any better solution ?
Somebody in a newsgroup dedicated to your OS probably does. Your
question has nothing to do with C++ language.


I'm sorry, but exactly how is this OS specific ? The only thing I said
that's OS related was that I'm using the select() call... this is mainly
to illustrate how the reactor works.


Threads, data queues, mutual exclusion, sockets?
Now, this problem is simply what the best solution is to combine the
slices of data received from multiple socket in multiple threads. I
don't see how this is OS-specific.
I don't see what (if anything) it has to do with standard C++, which
knows nothing of sockets or threads.
I see questions here about how to use the if() statement; no offense,
but I think to the average C++ software engineer, this is a far more
interesting question.


Huh? I didn't see anything asking how to use the if() statement. It's
not exactly a difficult statement to use, after all:

if (<condition>) <statement> [ else <statement> ]

Would you like to reword your question in a way which is about standard
C++, since everyone else seems to have misunderstood what you were
asking?

Chris C
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1512
by: SuryaPrakash Patel via SQLMonster.com | last post by:
Dear Reader I am trying to design a database. How can I make best Judgement that Indexing (which I am trying to fix during Diagram Desingning process)is ok. I am able to identify the best candidate for the indexing. Below is the details I want to understand: Area ZIP
12
1892
by: James Brown | last post by:
Hi all, Having problems designing a template-class. I'll describe my scenario first then show what I've come up with so far: Need a class to provide pointer/array-like access to an area of physical memory located on a piece of custom hardware - this memory is only accessible using machine specific i/o so I want to hide all this in a class. I'm imagining
13
16736
by: Charulatha Kalluri | last post by:
Hi, I'm implementing a Matrix class, as part of a project. This is the interface I've designed: class Matrix( )
6
2400
by: Darren | last post by:
X-No-Archive Hi all, Can anyone help me with structuring the data in a small tool I have to build? I'm trying to work out if there's a design pattern or data structure that would remove some of the dependencies. I am designing an animation tool.
7
3643
by: Dave | last post by:
I have a system that basically stores a database within a database (I'm sure lots have you have done this before in some form or another). At the end of the day, I'm storing the actual data generically in a column of type nvarchar(4000), but I want to add support for unlimited text. I want to do this in a smart fashion. Right now I am leaning towards putting 2 nullable Value fields: ValueLong ntext nullable ValueShort nvarchar(4000)...
1
2131
by: RC | last post by:
I have an Access 2002 database with many tables and forms (but just to keep things simple, let's say the DB has one Table "Table1" and one Form "Form1"). I have managed to cobble together so much complex code to add records and edit records I need to step back and ask you all what is the proper way to do this. The database is DAO. The table has Columns SerialNumber, CPU, HardDrive and Model. I am trying to use a Form to fill out the...
6
2952
by: Gary James | last post by:
This may not be a direct C# question, but since I'll be using using C# for development, I thought I'd pose the question here. I'll soon be involved in the design of a new software product that will employ a software "Plug-In" architecture. Taking the plug-in route will give us a design that can adapt to, as yet, undefined future requirements (within the scope of the plug-in interface spec of course). In the past I've done this with...
2
2013
by: Lorenzo Castelli | last post by:
This is an old problem of mine. Basically I have an abstract base class which represents a generic iterator over a collection of elements, and various derived classes that implement the traversing on specific data structures. For each iterator I want to be able to specify the four possible const combinations, corresponding to the various void* for pointers, with the possibility to perform conversions from non-const to const just like...
3
3332
by: krzysztof.konopko | last post by:
Hello! I want to design a class hierarchy with one base abstract class, let's say CBase. I have a predicate that every object in the class hierarchy must have a parent object of type from this class hierarchy but only objects of some of these types can be a parent. Example: class CFruit : public CBase { }; class CBranch : public CBase { };
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.