Designing a proper server model

L

Leon Mergen

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++
 
V

Victor Bazarov

Leon Mergen said:
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
 
L

Leon Mergen

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
 
V

Victor Bazarov

Leon Mergen said:
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.programming.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
 
L

Leon Mergen

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.programming.threads .

Regards,

Leon Mergen
 
C

Chris Croughton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top