Re: Writing on a common socket from multiple threads
Re: Writing on a common socket from multiple threads
- Subject: Re: Writing on a common socket from multiple threads
- From: Nathan Sims <email@hidden>
- Date: Wed, 01 Jun 2011 17:16:02 -0700
On Jun 1, 2011, at 5:03 PM, Quinn The Eskimo! wrote:
>
> On 1 Jun 2011, at 16:50, Josh Graessley wrote:
>
>> One common problem with writing on a single socket from multiple threads is interleaved data.
>
> Another one relates to closing. You have to make sure that you carefully coordinate the close of the socket, lest you run into problems like this:
>
> 1. thread A is writing to socket X via fd
>
> 2. thread B decides its time to close fd
>
> 3. thread C opens a file Y and gets back fd as the file descriptor
>
> 4. thread A is now writing to file Y rather than socket X
For the moment, the socket remains open always (unless there's an error, like EPIPE). The reason I use the spinlocks is to avoid interleaving data, so the process is essentially single-threaded in its socket access, just to keep things simple.
I was wondering if there might be any kind of interaction when having open sockets, of type TCP/IP and Bonjour/UDP?
bj_socket = socket(AF_INET,SOCK_DGRAM,0);
. . .
ip_socket = socket(AF_INET,SOCK_STREAM,0);
The program reads from the DGRAM socket on a peer-to-peer connection, and then writes to the STREAM socket over a wifi connection (both are using the default en0). After that point, writes to the STREAM socket return EPIPE.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden