kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: kgio@librelist.com
Subject: Re: [PATCH 1/2] add `#kgio_writev` and `#kgio_trywritev`
Date: Wed, 30 May 2012 04:55:34 +0000	[thread overview]
Message-ID: <20120530045534.GA26441@dcvr.yhbt.net> (raw)
In-Reply-To: 4FC5A257.8060201@gmail.com

Yura Sokolov <funny.falcon@gmail.com> wrote:
> 29.05.2012 23:11, Eric Wong написал:
> > Sokolov Yura 'funny-falcon<funny.falcon@gmail.com>  wrote:
> >> Since both methods dups array and strings in it, `#kgio_writev` semantic
> >> a bit different from `#kgio_write`: it does not react on changes to
> >> array/strings that made in other thread. But I think, this way is more
> >> correct.
> >
> > Perhaps we should use rb_str_locktmp()?
> 
> I think, it is good idea :) And use it at `#kgio_write` as well.
> 
> I want to redo patch: #kgio_trywritev needs not dup-ing or freeze-ing/lock-ing,
> and this method is primary for me.
> May be, array should be slice-ed when it is not fully written? It will do
> the good job for #kgio_write too.
> 
> (I ommit some formatting comments, will fix them)

OK, thank you for doing this :>

> >> +				n -= RSTRING_LEN(str);
> >> +				rb_ary_shift(a->buf);
> >> +				a->vec++;
> >
> > Probably better to store the array offset instead of shifting
> > Array#shift is O(n).
> Well, in Ruby1.9 it is O(1) if not intermixed with other modifying calls.
> I'll use rb_ary_subseq, it is also O(1) in Ruby1.9.

rb_ary_subseq can still copy or (at the very least) alloc a new object,
though.  Just storing the offset as a long and calling rb_ary_entry()
will be simplest, I think.

Some of the optimizations in MRI array.c make it hard to follow :<

> >> +retry:
> >> +	iov_cnt = RARRAY_LEN(a.buf);
> >> +	if (iov_cnt>  iov_max) iov_cnt = iov_max;
> >> +	n = (long)writev(a.fd, a.vec, iov_cnt);
> >> +	if (writev_check(&a, n, "writev", io_wait) != 0)
> >> +		goto retry;
> >> +	if (TYPE(a.buf) != T_SYMBOL)
> >> +		kgio_autopush_write(io);
> >> +	return a.buf;
> >
> > (I'm not fully awake): You do retry when truncating to iov_max, right?
> 
> Retry is done cause writev_check returns -1

OK, thanks for confirming that.

> I'll try to redo patch today or tomorrow.

Thank you again!

      reply	other threads:[~2012-05-30  4:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-29 15:00 [PATCH 1/2] add `#kgio_writev` and `#kgio_trywritev` Sokolov Yura 'funny-falcon
2012-05-29 15:00 ` [PATCH 2/2] tests for " Sokolov Yura 'funny-falcon
2012-05-29 19:13   ` Eric Wong
2012-05-29 19:11 ` [PATCH 1/2] add " Eric Wong
2012-05-30  4:30   ` Yura Sokolov
2012-05-30  4:55     ` Eric Wong [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

  List information: https://yhbt.net/kgio/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120530045534.GA26441@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=kgio@librelist.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.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kgio.git/

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 read-only IMAP folder(s) and NNTP newsgroup(s).