recv() vs. close()
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > recv() vs. close()




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    recv() vs. close()  
Martin Vuille


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-20-07 06: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.





[ Post a follow-up to this message ]



    Re: recv() vs. close()  
Rainer Weikusat


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-20-07 06: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.





[ Post a follow-up to this message ]



    Re: recv() vs. close()  
Martin Vuille


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-20-07 06: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.





[ Post a follow-up to this message ]



    Re: recv() vs. close()  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-22-07 06: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 ***





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:39 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register