From: "Michael T Kerrisk" <mtk-lists@gmx.net>
To: bert hubert <ahu@ds9a.nl>
Cc: netdev@oss.sgi.com
Subject: Re: Strangeness when write()-ing zero-length datagrams
Date: Mon, 9 Aug 2004 17:59:00 +0200 (MEST) [thread overview]
Message-ID: <10578.1092067140@www39.gmx.net> (raw)
In-Reply-To: 20040809154057.GA30659@outpost.ds9a.nl
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 2638 bytes --]
Bert,
> > On Linux 2.4.26 and 2.6.7, if we connect a datagram socket and
> > then use write() to send 0 bytes, a datagram is NOT generated
> > (this happens in both the Unix and Internet domains).
> > Datagrams are generated in this case for send() and sendto()
> > though.
>
> Some postings were made about this some time ago,
I didn't find anything with google or archive seach -- do
you have any more specific reference on this thread?
> it appears SUS has an
> opinion on zero byte writes:
>
> If nbyte is 0, write() will return 0 and have no other results if the
> file is a regular file; otherwise, the results are unspecified.
> http://www.opengroup.org/onlinepubs/007908799/xsh/write.html
>
> The send(2) manpage states:
>
> The send() function is identical to sendto() with a null pointer dest_len
> argument, and to write() if no flags are used.
>
> Which means that a zero byte send() without flags is unspecified.
Yes, but on Linux write(fd, buf, 0) != send(fd, buf, 0, 0), which
does seem inconsistent. And as I noted, all the other implementations
I tested behave differently from Linux.
(Just so I'm sure we have our scenarios clear, I'm referring to
the following:
HOST-A HOST-B
create datagram socket
bind socket to
INADDR_ANY:port-x
create datagram socket
connect socket to
HOST-B:port-x
Now the following behave
differently:
write(fd, buf, 0);
send(fd, buf, 0, 0);
)
> Also note that it is hard if impossible to usefully inform userspace of
> the reception of a zery byte packet - returning 0 from recvfrom may
> also mean an 'orderly shutdown'.
Am I missing something? There isn't the notion of a true
connection with datagram sockets, and so no notion of an orderly
shutdown (I am assuming you are meaning some scenario where the
peer calls shutdown() or close()).
It is straightforward to detect a zero-length datagram: recvfrom()
returns 0.
> Do you actually have a need for zero byte packets?
No, but I discovered this difference during some testing that I
was doing, and then observed that it seems different from
most (all?) other implementations. It seemed worth documenting
this fact.
Cheers,
Michael
--
Michael Kerrisk
mtk-lists@gmx.net
NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler!
GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl
prev parent reply other threads:[~2004-08-09 15:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-09 14:38 Strangeness when write()-ing zero-length datagrams Michael T Kerrisk
2004-08-09 15:40 ` bert hubert
2004-08-09 15:59 ` Michael T Kerrisk [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10578.1092067140@www39.gmx.net \
--to=mtk-lists@gmx.net \
--cc=ahu@ds9a.nl \
--cc=netdev@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).