Unix sockets help

K

Karim

Hi,

I am working on a c++ project involving sockets and threads and I need
to ask a pretty basic question.

If you have a socket that every time it accepts a connection
(accept()) it spawns a thread with the identifier returned by accept
where the thread will write to the identifier using send().

My question is, are those identifiers returned by accept unique and
reliable enough s.t I can write (using send()) to them simultaneously
OR do I need a mutex on the writing code so that I don`t write to the
same physical socket by different sockets at the same time?

The current problem is that on the client side, I expect data like 123
and abc (for 2 different clients) and I am getting 1b3 and a2c, sort
of mixed data so that prompted me to ask this question.

Thanks.
 
G

Gianni Mariani

Karim said:
Hi,

I am working on a c++ project involving sockets and threads and I need
to ask a pretty basic question.

If you have a socket that every time it accepts a connection
(accept()) it spawns a thread with the identifier returned by accept
where the thread will write to the identifier using send().

My question is, are those identifiers returned by accept unique and
reliable enough s.t I can write (using send()) to them simultaneously
OR do I need a mutex on the writing code so that I don`t write to the
same physical socket by different sockets at the same time?

The current problem is that on the client side, I expect data like 123
and abc (for 2 different clients) and I am getting 1b3 and a2c, sort
of mixed data so that prompted me to ask this question.

comp.lang.c++ is not the right news group. Try comp.unix.programmer.

To answer your question - the "file descriptor" returned by accept is
unique to all the other "OPEN" file descriptors.

If you have a *nix system, there usually is a system call tracker
(strace on Linux). Trace the process (and threads) and you should get a
clear indication of what is going on.

But don't post system specific questions on comp.lang.c++. This NG is
specifically for the C++ language.
 

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

Similar Threads

UNIX datagram sockets 29
Sockets question 3
Sockets on Unix 4
Unix Sockets SOCK_DGRAM 2
Help for a newbie 13
udp sockets 2
Sockets 11
Sockets 1

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top