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

Unix sockets help

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

Feb 25 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Karim wrote:
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.
Feb 25 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.