caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oliver <oliver@first.in-berlin.de>
To: "Török Edwin" <edwin+ml-ocaml@etorok.net>
Cc: rixed@happyleptic.org, caml-list@inria.fr
Subject: Re: [Caml-list] Unix.single_write, doc and atomicity
Date: Wed, 6 Jun 2012 15:29:39 +0200	[thread overview]
Message-ID: <20120606132939.GE1854@siouxsie> (raw)
In-Reply-To: <4FCF584E.2000309@etorok.net>

Hello,


single_write-docs say:

  "Same as write, but attempts to write only once. Thus, if an error occurs,
  single_write guarantees that no data has been written."

Attempts does not mean guarantee.
If it fails, it will give an error.


But I wonder if
  "Thus, if an error occurs, single_write guarantees that no data has been written."
is correct for all devices and situations.

It may also be possible to write less bytes than one wants.
In this case "guarantees that no data has been written"
seems to be violated.

For these cases, the docs need to be corrected.

More precise IMHO would be:

  "If no error occured, all data has been written sucessfully in one attempt."

Ciao,
   Oliver 


On Wed, Jun 06, 2012 at 04:17:02PM +0300, Török Edwin wrote:
> On 06/06/2012 04:06 PM, rixed@happyleptic.org wrote:
> > I was reading the code for unix_single_write recently, and noticed two strange
> > things that I prefer to discuss here before filling the bug tracker with
> > dubious tickets.
> > 
> > First, the doc of Unix.single_write claims that this function "attemps to write
> > only once", although the underlying unix_single_write C function clearly loops
> > around a write if the buffer being written is larger than the internal buffer
> > (16K).
> 
> Are we looking at the same file / function?
> The one that loops is unix_write, I don't see any loops in unix_single_write:
> 
> CAMLprim value unix_single_write(value fd, value buf, value vofs, value vlen)
> {
>   long ofs, len;
>   int numbytes, ret;
>   char iobuf[UNIX_BUFFER_SIZE];
> 
>   Begin_root (buf);
>     ofs = Long_val(vofs);
>     len = Long_val(vlen);
>     ret = 0;
>     if (len > 0) {
>       numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len;
>       memmove (iobuf, &Byte(buf, ofs), numbytes);
>       enter_blocking_section();
>       ret = write(Int_val(fd), iobuf, numbytes);
>       leave_blocking_section();
>       if (ret == -1) uerror("single_write", Nothing);
>     }
>   End_roots();
>   return Val_int(ret);
> 
> 
> > 
> > So this boils down to : unix_single_write really should perform a single write!
> 
> AFAICT it does only a single write.
> 
> Best regards,
> --Edwin
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 

  reply	other threads:[~2012-06-06 13:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06 13:06 rixed
2012-06-06 13:17 ` Török Edwin
2012-06-06 13:29   ` oliver [this message]
2012-06-06 13:34   ` rixed
2012-06-16 23:11 ` Goswin von Brederlow

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=20120606132939.GE1854@siouxsie \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@inria.fr \
    --cc=edwin+ml-ocaml@etorok.net \
    --cc=rixed@happyleptic.org \
    /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).