From: Tomas Carnecky <tom@dbservice.com>
To: supervision@list.skarnet.org
Subject: runit: buffer_feed()
Date: Fri, 23 Jan 2009 14:06:30 +0100 [thread overview]
Message-ID: <4979C0D6.3000409@dbservice.com> (raw)
I'm looking at the buffer_feed() function in runit and I can't make
sense of it. I'm in the process of replacing all byte_* functions with
standard memcpy/memcmp etc, but I just don't see what this byte_copyr()
is supposed to do:
int buffer_feed(buffer *s)
{
int r;
if (s->p) return s->p;
r = oneread(s->op,s->fd,s->x,s->n);
if (r <= 0) return r;
s->p = r;
s->n -= r;
if (s->n > 0) byte_copyr(s->x + s->n,r,s->x);
return r;
}
byte_copyr() copies backwards, so you're reading/accessing bytes
_before_ s->x. Shouldn't that cause a SIGSEGV?
Also, what is ->p and ->n? ->n seems to be the offset into the ->s char
array, ->p the number of bytes currently in the buffer. It looks that
way if I look at buffer_peek(), but ->n is initialized to 'len', which
means that buffer_peek() just after the buffer is initialized returns a
pointer beyond the end of the buffer.. ? Also, ->n is decreased after
data is read into the buffer (using oneread). That doesn't make sense.
It's all very confusing.
Can sombody please explain how the code is supposed to work?
thanks
tom
next reply other threads:[~2009-01-23 13:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-23 13:06 Tomas Carnecky [this message]
2009-01-23 14:30 ` Charlie Brady
2009-01-23 14:57 ` Tomas Carnecky
2009-01-23 17:06 ` Laurent Bercot
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=4979C0D6.3000409@dbservice.com \
--to=tom@dbservice.com \
--cc=supervision@list.skarnet.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).