Re: Are sockets thread safe
- From: "jainarunk@xxxxxxxxx" <jainarunk@xxxxxxxxx>
- Date: 15 Jun 2006 08:36:21 -0700
Maxim Yegorushkin wrote:
jainarunk@xxxxxxxxx wrote:
Phil,
The need arose, because I am writing a client for a web server, where
each thread in
the client wraps its own request for a paraticular web page from the
server and writes
to the same web server on the other end of the same socket. And of
course each
thread would be interested to read the web page for it sent the
request. I hope it
explains.
You need a dispatcher thread that serializes http requests from
different threads and writes them to the socket. This thread or another
one should also read all the http responses from the socket and forward
them to where these responses are waited for.
Phil, in one of his postings suggested that I have multiple sockets.
My reasoning is that
by having multiple sockets.
1. The user may potentially want to access hundreds of pages and
creating a socket
per page will be very costly and will put undue/unnecessary resource
utilization.
2. Some of the classes in my implementation are private and the 'user'
does not have
access to creatation
3. User is given the responisbility to create the thread and not the
client I am writing.
Because I do not know before hand what would user intend to do.
I will opt for a dispatcher thread solution, because it looks more
promising. However I
will need some guide lines as to how to implement a dispatcher thread,
what data
structures I will have to create, the communication channel between
individual threads
and the dispatcher thread, and the performance cost analysis if any.
Thanks for your support and enlightened discussion.
In any case, there should be no more than one thread simultaneously
reading/writing the same stream socket. Otherwise data get screwed up.
I was implementing locks and condition variables to ensure that data
does not
corrupted.
Nagrik
.
- Follow-Ups:
- Re: Are sockets thread safe
- From: Maxim Yegorushkin
- Re: Are sockets thread safe
- From: Rick Jones
- Re: Are sockets thread safe
- From: Phil Frisbie, Jr.
- Re: Are sockets thread safe
- References:
- Are sockets thread safe
- From: jainarunk
- Re: Are sockets thread safe
- From: Dan N
- Re: Are sockets thread safe
- From: jainarunk@xxxxxxxxx
- Re: Are sockets thread safe
- From: Phil Frisbie, Jr.
- Re: Are sockets thread safe
- From: jainarunk@xxxxxxxxx
- Re: Are sockets thread safe
- From: Maxim Yegorushkin
- Are sockets thread safe
- Prev by Date: Re: Networking two laptops
- Next by Date: Re: Are sockets thread safe
- Previous by thread: Re: Are sockets thread safe
- Next by thread: Re: Are sockets thread safe
- Index(es):
Relevant Pages
|