By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 839 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Designing a proper server model

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
"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

P: n/a
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

P: n/a
"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.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
Jul 23 '05 #4

P: n/a
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.programming.threads .

Regards,

Leon Mergen

Jul 23 '05 #5

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.