recv() vs. close() - Unix

This is a discussion on recv() vs. close() - Unix ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: recv() vs. close()

  1. recv() vs. close()

    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.

  2. Re: recv() vs. close()

    Martin Vuille 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.

  3. Re: recv() vs. close()

    Rainer Weikusat 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.

  4. Re: recv() vs. close()

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

    > Martin Vuille 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.


    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 ***

+ Reply to Thread