Unix Programming - recv() vs. close()

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2007 > recv() vs. close()





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author recv() vs. close()
Martin Vuille

2007-04-20, 1:24 pm

I'm new to socket programming, so apologies in advance if my use of
terminology is incorrect or confusing. Please feel free to correct
me.

I'm trying to understand a problem in some code I did not write and
which I cannot post here.

Let's say that I have a Unix-domain socket (PF_UNIX) in datagram
(SOCK_DGRAM) and multicast mode (UNIX_SET_MCAST in setsockopt), with
membership established to a "wildcard" multicast address
(UNIX_ADD_MEMBERSHIP in setsockopt, with sun_family = PF_UNIX,
sun_path[0] = 0).

One process has a recv() pending on its socket.

Another process does a sendmsg() to its socket and then immediately
does a close() on it.

What will the first process see? Will it receive the message and then
an error on the next recv(), or only an error, or ??? Which error?

How would this change if instead of two processes, we have two
threads in the same process, and both are using the same socket/FD?

In case it matters, this is on Linux 2.4.

--
I do not want replies; please follow-up to the group.
Rainer Weikusat

2007-04-20, 1:24 pm

Martin Vuille <jpmv27@yahoo.com> writes:
> I'm new to socket programming, so apologies in advance if my use of
> terminology is incorrect or confusing. Please feel free to correct
> me.
>
> I'm trying to understand a problem in some code I did not write and
> which I cannot post here.
>
> Let's say that I have a Unix-domain socket (PF_UNIX) in datagram
> (SOCK_DGRAM) and multicast mode (UNIX_SET_MCAST in setsockopt), with
> membership established to a "wildcard" multicast address
> (UNIX_ADD_MEMBERSHIP in setsockopt, with sun_family = PF_UNIX,
> sun_path[0] = 0).
>
> One process has a recv() pending on its socket.
>
> Another process does a sendmsg() to its socket and then immediately
> does a close() on it.
>
> What will the first process see? Will it receive the message and then
> an error on the next recv(), or only an error, or ??? Which error?


Only the message. The next recv will then block until a further
message is received. Since UDP is connection-less, closing a UDP
socket is a purely local operation.
Martin Vuille

2007-04-20, 1:24 pm

Rainer Weikusat <rweikusat@mssgmbh.com> wrote in
news:87ps5zrpsr.fsf@fever.mssgmbh.com:

>
> Only the message. The next recv will then block until a further
> message is received. Since UDP is connection-less, closing a UDP
> socket is a purely local operation.
>


Doh! Obvious in retrospect.

Thanks!
MV

--
I do not want replies; please follow-up to the group.
Barry Margolin

2007-04-22, 1:20 am

In article <87ps5zrpsr.fsf@fever.mssgmbh.com>,
Rainer Weikusat <rweikusat@mssgmbh.com> wrote:

> Martin Vuille <jpmv27@yahoo.com> writes:
>
> Only the message. The next recv will then block until a further
> message is received. Since UDP is connection-less, closing a UDP
> socket is a purely local operation.


He's not using UDP, since he's using a Unix-domain socket, not an
Internet socket. But your explanation is true for datagrams in general,
not just UDP.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com