f



Threads reading from sockets & writing into a pipe

Hi to all!
As from subject, I have inside a process some threads
that communicate, each of them, with distinct socket streams.
Also, after reading data from socket each thread must write
that data into a pipe (created by the process).
Now, I got that running the code each thread reads (from the socket)
and writes (into the pipe) exactly 1 byte (!) of data, concurrently;
sometimes more than 1 byte (4 at all).

Is there any problem calling a function in a thread that uses a read()
function
on a socket descriptor?
If no, does anybody know the reasons ?
Please, help me!
Thanks a lot,
    S c o u t.



0
scout
11/22/2003 3:42:44 PM
comp.programming.threads 4878 articles. 1 followers. Post Follow

5 Replies
518 Views

Similar Articles

[PageSpeed] 49

"scout" <user@domain.it> wrote in message
news:UtLvb.138709$e6.4980008@twister2.libero.it...
> Hi to all!
> As from subject, I have inside a process some threads
> that communicate, each of them, with distinct socket streams.

    By "distinct", do you mean that each thread has its own stream?

> Also, after reading data from socket each thread must write
> that data into a pipe (created by the process).
> Now, I got that running the code each thread reads (from the socket)
> and writes (into the pipe) exactly 1 byte (!) of data, concurrently;
> sometimes more than 1 byte (4 at all).

    Okay. Is the socket TCP, UDP or what? Are you talking about reading or
writing more than 1 byte? If you only want to read or write one byte, just
only ask for one byte.

> Is there any problem calling a function in a thread that uses a read()
> function
> on a socket descriptor?

    Nope, no problem.

> If no, does anybody know the reasons ?

    Reasons for what?

    DS


0
David
11/22/2003 9:49:55 PM
Let me explain myself better:
1) each thread has its own socket stream, using TCP protocol;
2) each thread write on the same PIPE;
3) Of course, I want to read more than 1 byte!
        Is the scheduling of the thread more faster than read() function
task ?
4) I would that the read() function "reads" more bytes at a stroke.

Is it more clear now?
Thanks.
Bye, Scout

"David Schwartz" <davids@webmaster.com> ha scritto nel messaggio
news:bpolm4$52u$1@nntp.webmaster.com...
>
> "scout" <user@domain.it> wrote in message
> news:UtLvb.138709$e6.4980008@twister2.libero.it...
> > Hi to all!
> > As from subject, I have inside a process some threads
> > that communicate, each of them, with distinct socket streams.
>
>     By "distinct", do you mean that each thread has its own stream?
>
> > Also, after reading data from socket each thread must write
> > that data into a pipe (created by the process).
> > Now, I got that running the code each thread reads (from the socket)
> > and writes (into the pipe) exactly 1 byte (!) of data, concurrently;
> > sometimes more than 1 byte (4 at all).
>
>     Okay. Is the socket TCP, UDP or what? Are you talking about reading or
> writing more than 1 byte? If you only want to read or write one byte, just
> only ask for one byte.
>
> > Is there any problem calling a function in a thread that uses a read()
> > function
> > on a socket descriptor?
>
>     Nope, no problem.
>
> > If no, does anybody know the reasons ?
>
>     Reasons for what?
>
>     DS
>
>


0
scout
11/23/2003 12:43:47 PM
"scout" <user@domain.it> wrote in message
news:7Y1wb.136503$vO5.5316600@twister1.libero.it...

> Let me explain myself better:
> 1) each thread has its own socket stream, using TCP protocol;
> 2) each thread write on the same PIPE;
> 3) Of course, I want to read more than 1 byte!
>         Is the scheduling of the thread more faster than read() function
> task ?

    Quite probably.

> 4) I would that the read() function "reads" more bytes at a stroke.

> Is it more clear now?

    Then you're going to have to read slower or send faster. It's not
surprising that the computer is much faster than the network.

    DS


0
David
11/24/2003 1:04:29 AM
I've found that the one byte read by the thread (by each thread)
is AT ALL TIMES the first byte of the socket stream;
the read(socket_ds, buffer, sizeof(buffer)) reads ever the same byte!
I think that inside a thread is possible to use a system call but
isn't possible to open a tcp flow (socket() function) directly,
because the socket descriptor must be outside the thread
(as a global variable)...a data shared among the threads.
What do you think?
thx
 Scout.

>
> > Let me explain myself better:
> > 1) each thread has its own socket stream, using TCP protocol;
> > 2) each thread write on the same PIPE;
> > 3) Of course, I want to read more than 1 byte!
> >         Is the scheduling of the thread more faster than read() function
> > task ?
>
>     Quite probably.
>
> > 4) I would that the read() function "reads" more bytes at a stroke.
>
> > Is it more clear now?
>
>     Then you're going to have to read slower or send faster. It's not
> surprising that the computer is much faster than the network.
>
>     DS


0
dan
11/24/2003 5:57:50 PM
"dan" <dan@dare.com> wrote in message
news:yErwb.143157$e6.5195506@twister2.libero.it...

> I've found that the one byte read by the thread (by each thread)
> is AT ALL TIMES the first byte of the socket stream;
> the read(socket_ds, buffer, sizeof(buffer)) reads ever the same byte!

    This is probably because you're ignoring the return value of the 'read'
call.

> I think that inside a thread is possible to use a system call but
> isn't possible to open a tcp flow (socket() function) directly,
> because the socket descriptor must be outside the thread

    There is no such thing as 'outside the thread'.

> (as a global variable)...a data shared among the threads.
> What do you think?

    That makes no sense.

    DS


0
David
11/24/2003 6:07:33 PM
Reply: