CLEANUP: channel: use 'chn' instead of 'buf' as local variable names

It's too confusing to see buf->buf everywhere where the first buf is
a channel. Let's fix this now.
This commit is contained in:
Willy Tarreau 2012-10-12 23:11:02 +02:00
parent cdbdd52a38
commit 974ced6305
2 changed files with 176 additions and 176 deletions

View File

@ -39,27 +39,27 @@ extern struct pool_head *pool2_channel;
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_channel();
unsigned long long channel_forward(struct channel *buf, unsigned long long bytes);
unsigned long long channel_forward(struct channel *chn, unsigned long long bytes);
/* SI-to-channel functions working with buffers */
int bi_putblk(struct channel *buf, const char *str, int len);
int bi_putchr(struct channel *buf, char c);
int bo_inject(struct channel *buf, const char *msg, int len);
int bo_getline(struct channel *buf, char *str, int len);
int bo_getblk(struct channel *buf, char *blk, int len, int offset);
int bi_putblk(struct channel *chn, const char *str, int len);
int bi_putchr(struct channel *chn, char c);
int bo_inject(struct channel *chn, const char *msg, int len);
int bo_getline(struct channel *chn, char *str, int len);
int bo_getblk(struct channel *chn, char *blk, int len, int offset);
/* Initialize all fields in the channel. */
static inline void channel_init(struct channel *buf)
static inline void channel_init(struct channel *chn)
{
buf->buf.o = 0;
buf->buf.i = 0;
buf->buf.p = buf->buf.data;
buf->to_forward = 0;
buf->total = 0;
buf->pipe = NULL;
buf->analysers = 0;
buf->cons = NULL;
buf->flags = 0;
chn->buf.o = 0;
chn->buf.i = 0;
chn->buf.p = chn->buf.data;
chn->to_forward = 0;
chn->total = 0;
chn->pipe = NULL;
chn->analysers = 0;
chn->cons = NULL;
chn->flags = 0;
}
/*********************************************************************/
@ -81,36 +81,36 @@ static inline unsigned int channel_is_empty(struct channel *c)
* close to happen. The test is optimized to avoid as many operations as
* possible for the fast case and to be used as an "if" condition.
*/
static inline int channel_full(const struct channel *b)
static inline int channel_full(const struct channel *chn)
{
int rem = b->buf.size;
int rem = chn->buf.size;
rem -= b->buf.o;
rem -= b->buf.i;
rem -= chn->buf.o;
rem -= chn->buf.i;
if (!rem)
return 1; /* buffer already full */
if (b->to_forward >= b->buf.size ||
(CHN_INFINITE_FORWARD < MAX_RANGE(typeof(b->buf.size)) && // just there to ensure gcc
b->to_forward == CHN_INFINITE_FORWARD)) // avoids the useless second
return 0; // test whenever possible
if (chn->to_forward >= chn->buf.size ||
(CHN_INFINITE_FORWARD < MAX_RANGE(typeof(chn->buf.size)) && // just there to ensure gcc
chn->to_forward == CHN_INFINITE_FORWARD)) // avoids the useless second
return 0; // test whenever possible
rem -= global.tune.maxrewrite;
rem += b->buf.o;
rem += b->to_forward;
rem += chn->buf.o;
rem += chn->to_forward;
return rem <= 0;
}
/* Returns true if the channel's input is already closed */
static inline int channel_input_closed(struct channel *buf)
static inline int channel_input_closed(struct channel *chn)
{
return ((buf->flags & CF_SHUTR) != 0);
return ((chn->flags & CF_SHUTR) != 0);
}
/* Returns true if the channel's output is already closed */
static inline int channel_output_closed(struct channel *buf)
static inline int channel_output_closed(struct channel *chn)
{
return ((buf->flags & CF_SHUTW) != 0);
return ((chn->flags & CF_SHUTW) != 0);
}
/* Check channel timeouts, and set the corresponding flags. The likely/unlikely
@ -118,50 +118,50 @@ static inline int channel_output_closed(struct channel *buf)
* set if there was activity on the channel. That way, we don't have to update
* the timeout on every I/O. Note that the analyser timeout is always checked.
*/
static inline void channel_check_timeouts(struct channel *b)
static inline void channel_check_timeouts(struct channel *chn)
{
if (likely(!(b->flags & (CF_SHUTR|CF_READ_TIMEOUT|CF_READ_ACTIVITY|CF_READ_NOEXP))) &&
unlikely(tick_is_expired(b->rex, now_ms)))
b->flags |= CF_READ_TIMEOUT;
if (likely(!(chn->flags & (CF_SHUTR|CF_READ_TIMEOUT|CF_READ_ACTIVITY|CF_READ_NOEXP))) &&
unlikely(tick_is_expired(chn->rex, now_ms)))
chn->flags |= CF_READ_TIMEOUT;
if (likely(!(b->flags & (CF_SHUTW|CF_WRITE_TIMEOUT|CF_WRITE_ACTIVITY))) &&
unlikely(tick_is_expired(b->wex, now_ms)))
b->flags |= CF_WRITE_TIMEOUT;
if (likely(!(chn->flags & (CF_SHUTW|CF_WRITE_TIMEOUT|CF_WRITE_ACTIVITY))) &&
unlikely(tick_is_expired(chn->wex, now_ms)))
chn->flags |= CF_WRITE_TIMEOUT;
if (likely(!(b->flags & CF_ANA_TIMEOUT)) &&
unlikely(tick_is_expired(b->analyse_exp, now_ms)))
b->flags |= CF_ANA_TIMEOUT;
if (likely(!(chn->flags & CF_ANA_TIMEOUT)) &&
unlikely(tick_is_expired(chn->analyse_exp, now_ms)))
chn->flags |= CF_ANA_TIMEOUT;
}
/* Erase any content from channel <buf> and adjusts flags accordingly. Note
* that any spliced data is not affected since we may not have any access to
* it.
*/
static inline void channel_erase(struct channel *buf)
static inline void channel_erase(struct channel *chn)
{
buf->buf.o = 0;
buf->buf.i = 0;
buf->to_forward = 0;
buf->buf.p = buf->buf.data;
chn->buf.o = 0;
chn->buf.i = 0;
chn->to_forward = 0;
chn->buf.p = chn->buf.data;
}
/* marks the channel as "shutdown" ASAP for reads */
static inline void channel_shutr_now(struct channel *buf)
static inline void channel_shutr_now(struct channel *chn)
{
buf->flags |= CF_SHUTR_NOW;
chn->flags |= CF_SHUTR_NOW;
}
/* marks the channel as "shutdown" ASAP for writes */
static inline void channel_shutw_now(struct channel *buf)
static inline void channel_shutw_now(struct channel *chn)
{
buf->flags |= CF_SHUTW_NOW;
chn->flags |= CF_SHUTW_NOW;
}
/* marks the channel as "shutdown" ASAP in both directions */
static inline void channel_abort(struct channel *buf)
static inline void channel_abort(struct channel *chn)
{
buf->flags |= CF_SHUTR_NOW | CF_SHUTW_NOW;
buf->flags &= ~CF_AUTO_CONNECT;
chn->flags |= CF_SHUTR_NOW | CF_SHUTW_NOW;
chn->flags &= ~CF_AUTO_CONNECT;
}
/* Installs <func> as a hijacker on the channel <b> for session <s>. The hijack
@ -170,56 +170,56 @@ static inline void channel_abort(struct channel *buf)
* during this first call.
*/
static inline void channel_install_hijacker(struct session *s,
struct channel *b,
struct channel *chn,
void (*func)(struct session *, struct channel *))
{
b->hijacker = func;
b->flags |= CF_HIJACK;
func(s, b);
chn->hijacker = func;
chn->flags |= CF_HIJACK;
func(s, chn);
}
/* Releases the channel from hijacking mode. Often used by the hijack function */
static inline void channel_stop_hijacker(struct channel *buf)
static inline void channel_stop_hijacker(struct channel *chn)
{
buf->flags &= ~CF_HIJACK;
chn->flags &= ~CF_HIJACK;
}
/* allow the consumer to try to establish a new connection. */
static inline void channel_auto_connect(struct channel *buf)
static inline void channel_auto_connect(struct channel *chn)
{
buf->flags |= CF_AUTO_CONNECT;
chn->flags |= CF_AUTO_CONNECT;
}
/* prevent the consumer from trying to establish a new connection, and also
* disable auto shutdown forwarding.
*/
static inline void channel_dont_connect(struct channel *buf)
static inline void channel_dont_connect(struct channel *chn)
{
buf->flags &= ~(CF_AUTO_CONNECT|CF_AUTO_CLOSE);
chn->flags &= ~(CF_AUTO_CONNECT|CF_AUTO_CLOSE);
}
/* allow the producer to forward shutdown requests */
static inline void channel_auto_close(struct channel *buf)
static inline void channel_auto_close(struct channel *chn)
{
buf->flags |= CF_AUTO_CLOSE;
chn->flags |= CF_AUTO_CLOSE;
}
/* prevent the producer from forwarding shutdown requests */
static inline void channel_dont_close(struct channel *buf)
static inline void channel_dont_close(struct channel *chn)
{
buf->flags &= ~CF_AUTO_CLOSE;
chn->flags &= ~CF_AUTO_CLOSE;
}
/* allow the producer to read / poll the input */
static inline void channel_auto_read(struct channel *buf)
static inline void channel_auto_read(struct channel *chn)
{
buf->flags &= ~CF_DONT_READ;
chn->flags &= ~CF_DONT_READ;
}
/* prevent the producer from read / poll the input */
static inline void channel_dont_read(struct channel *buf)
static inline void channel_dont_read(struct channel *chn)
{
buf->flags |= CF_DONT_READ;
chn->flags |= CF_DONT_READ;
}
@ -232,13 +232,13 @@ static inline void channel_dont_read(struct channel *buf)
* buffer, which ensures that once all pending data are forwarded, the
* buffer still has global.tune.maxrewrite bytes free. The result is
* between 0 and global.tune.maxrewrite, which is itself smaller than
* any buf->size.
* any chn->size.
*/
static inline int buffer_reserved(const struct channel *buf)
static inline int buffer_reserved(const struct channel *chn)
{
int ret = global.tune.maxrewrite - buf->to_forward - buf->buf.o;
int ret = global.tune.maxrewrite - chn->to_forward - chn->buf.o;
if (buf->to_forward == CHN_INFINITE_FORWARD)
if (chn->to_forward == CHN_INFINITE_FORWARD)
return 0;
if (ret <= 0)
return 0;
@ -247,11 +247,11 @@ static inline int buffer_reserved(const struct channel *buf)
/* Return the max number of bytes the buffer can contain so that once all the
* pending bytes are forwarded, the buffer still has global.tune.maxrewrite
* bytes free. The result sits between buf->size - maxrewrite and buf->size.
* bytes free. The result sits between chn->size - maxrewrite and chn->size.
*/
static inline int buffer_max_len(const struct channel *buf)
static inline int buffer_max_len(const struct channel *chn)
{
return buf->buf.size - buffer_reserved(buf);
return chn->buf.size - buffer_reserved(chn);
}
/* Return the amount of bytes that can be written into the buffer at once,
@ -267,24 +267,24 @@ static inline int buffer_contig_space_res(const struct channel *chn)
* is close to happen. The test is optimized to avoid as many operations as
* possible for the fast case.
*/
static inline int bi_avail(const struct channel *b)
static inline int bi_avail(const struct channel *chn)
{
int rem = b->buf.size;
int rem = chn->buf.size;
int rem2;
rem -= b->buf.o;
rem -= b->buf.i;
rem -= chn->buf.o;
rem -= chn->buf.i;
if (!rem)
return rem; /* buffer already full */
if (b->to_forward >= b->buf.size ||
(CHN_INFINITE_FORWARD < MAX_RANGE(typeof(b->buf.size)) && // just there to ensure gcc
b->to_forward == CHN_INFINITE_FORWARD)) // avoids the useless second
return rem; // test whenever possible
if (chn->to_forward >= chn->buf.size ||
(CHN_INFINITE_FORWARD < MAX_RANGE(typeof(chn->buf.size)) && // just there to ensure gcc
chn->to_forward == CHN_INFINITE_FORWARD)) // avoids the useless second
return rem; // test whenever possible
rem2 = rem - global.tune.maxrewrite;
rem2 += b->buf.o;
rem2 += b->to_forward;
rem2 += chn->buf.o;
rem2 += chn->to_forward;
if (rem > rem2)
rem = rem2;
@ -298,16 +298,16 @@ static inline int bi_avail(const struct channel *b)
* forwarding is stopped. This is mainly to be used to send error messages
* after existing data.
*/
static inline void bi_erase(struct channel *buf)
static inline void bi_erase(struct channel *chn)
{
if (!buf->buf.o)
return channel_erase(buf);
if (!chn->buf.o)
return channel_erase(chn);
buf->to_forward = 0;
if (!buf->buf.i)
chn->to_forward = 0;
if (!chn->buf.i)
return;
buf->buf.i = 0;
chn->buf.i = 0;
}
/*
@ -315,48 +315,48 @@ static inline void bi_erase(struct channel *buf)
* when data have been read directly from the buffer. It is illegal to call
* this function with <len> causing a wrapping at the end of the buffer. It's
* the caller's responsibility to ensure that <len> is never larger than
* buf->o. Channel flag WRITE_PARTIAL is set.
* chn->o. Channel flag WRITE_PARTIAL is set.
*/
static inline void bo_skip(struct channel *buf, int len)
static inline void bo_skip(struct channel *chn, int len)
{
buf->buf.o -= len;
chn->buf.o -= len;
if (buffer_len(&buf->buf) == 0)
buf->buf.p = buf->buf.data;
if (buffer_len(&chn->buf) == 0)
chn->buf.p = chn->buf.data;
/* notify that some data was written to the SI from the buffer */
buf->flags |= CF_WRITE_PARTIAL;
chn->flags |= CF_WRITE_PARTIAL;
}
/* Tries to copy chunk <chunk> into the channel's buffer after length controls.
* The buf->o and to_forward pointers are updated. If the channel's input is
* The chn->o and to_forward pointers are updated. If the channel's input is
* closed, -2 is returned. If the block is too large for this buffer, -3 is
* returned. If there is not enough room left in the buffer, -1 is returned.
* Otherwise the number of bytes copied is returned (0 being a valid number).
* Channel flag READ_PARTIAL is updated if some data can be transferred. The
* chunk's length is updated with the number of bytes sent.
*/
static inline int bi_putchk(struct channel *buf, struct chunk *chunk)
static inline int bi_putchk(struct channel *chn, struct chunk *chunk)
{
int ret;
ret = bi_putblk(buf, chunk->str, chunk->len);
ret = bi_putblk(chn, chunk->str, chunk->len);
if (ret > 0)
chunk->len -= ret;
return ret;
}
/* Tries to copy string <str> at once into the channel's buffer after length
* controls. The buf->o and to_forward pointers are updated. If the channel's
* controls. The chn->o and to_forward pointers are updated. If the channel's
* input is closed, -2 is returned. If the block is too large for this buffer,
* -3 is returned. If there is not enough room left in the buffer, -1 is
* returned. Otherwise the number of bytes copied is returned (0 being a valid
* number). Channel flag READ_PARTIAL is updated if some data can be
* transferred.
*/
static inline int bi_putstr(struct channel *buf, const char *str)
static inline int bi_putstr(struct channel *chn, const char *str)
{
return bi_putblk(buf, str, strlen(str));
return bi_putblk(chn, str, strlen(str));
}
/*
@ -364,17 +364,17 @@ static inline int bi_putstr(struct channel *buf, const char *str)
* channel is closed, return -2. If the buffer is just empty, return -1. The
* buffer's pointer is not advanced, it's up to the caller to call bo_skip(buf,
* 1) when it has consumed the char. Also note that this function respects the
* buf->o limit.
* chn->o limit.
*/
static inline int bo_getchr(struct channel *buf)
static inline int bo_getchr(struct channel *chn)
{
/* closed or empty + imminent close = -2; empty = -1 */
if (unlikely((buf->flags & CF_SHUTW) || channel_is_empty(buf))) {
if (buf->flags & (CF_SHUTW|CF_SHUTW_NOW))
if (unlikely((chn->flags & CF_SHUTW) || channel_is_empty(chn))) {
if (chn->flags & (CF_SHUTW|CF_SHUTW_NOW))
return -2;
return -1;
}
return *buffer_wrap_sub(&buf->buf, buf->buf.p - buf->buf.o);
return *buffer_wrap_sub(&chn->buf, chn->buf.p - chn->buf.o);
}

View File

@ -40,7 +40,7 @@ int init_channel()
* into account is returned. Directly touching ->to_forward will cause lockups
* when buf->o goes down to zero if nobody is ready to push the remaining data.
*/
unsigned long long channel_forward(struct channel *buf, unsigned long long bytes)
unsigned long long channel_forward(struct channel *chn, unsigned long long bytes)
{
unsigned int new_forward;
unsigned int forwarded;
@ -53,40 +53,40 @@ unsigned long long channel_forward(struct channel *buf, unsigned long long bytes
* once anyway.
*/
if (bytes <= ~0U) {
if (bytes32 <= buf->buf.i) {
if (bytes32 <= chn->buf.i) {
/* OK this amount of bytes might be forwarded at once */
if (!bytes32)
return 0;
b_adv(&buf->buf, bytes32);
b_adv(&chn->buf, bytes32);
return bytes;
}
}
forwarded = buf->buf.i;
b_adv(&buf->buf, buf->buf.i);
forwarded = chn->buf.i;
b_adv(&chn->buf, chn->buf.i);
/* Note: the case below is the only case where we may return
* a byte count that does not fit into a 32-bit number.
*/
if (likely(buf->to_forward == CHN_INFINITE_FORWARD))
if (likely(chn->to_forward == CHN_INFINITE_FORWARD))
return bytes;
if (likely(bytes == CHN_INFINITE_FORWARD)) {
buf->to_forward = bytes;
chn->to_forward = bytes;
return bytes;
}
new_forward = buf->to_forward + bytes - forwarded;
new_forward = chn->to_forward + bytes - forwarded;
bytes = forwarded; /* at least those bytes were scheduled */
if (new_forward <= buf->to_forward) {
if (new_forward <= chn->to_forward) {
/* integer overflow detected, let's assume no more than 2G at once */
new_forward = MID_RANGE(new_forward);
}
if (new_forward > buf->to_forward) {
bytes += new_forward - buf->to_forward;
buf->to_forward = new_forward;
if (new_forward > chn->to_forward) {
bytes += new_forward - chn->to_forward;
chn->to_forward = new_forward;
}
return bytes;
}
@ -98,14 +98,14 @@ unsigned long long channel_forward(struct channel *buf, unsigned long long bytes
* data. Note: this function appends data to the buffer's output and possibly
* overwrites any pending input data which are assumed not to exist.
*/
int bo_inject(struct channel *buf, const char *msg, int len)
int bo_inject(struct channel *chn, const char *msg, int len)
{
int max;
if (len == 0)
return -1;
if (len > buf->buf.size) {
if (len > chn->buf.size) {
/* we can't write this chunk and will never be able to, because
* it is larger than the buffer. This must be reported as an
* error. Then we return -2 so that writers that don't care can
@ -114,64 +114,64 @@ int bo_inject(struct channel *buf, const char *msg, int len)
return -2;
}
max = buffer_realign(&buf->buf);
max = buffer_realign(&chn->buf);
if (len > max)
return max;
memcpy(buf->buf.p, msg, len);
buf->buf.o += len;
buf->buf.p = b_ptr(&buf->buf, len);
buf->total += len;
memcpy(chn->buf.p, msg, len);
chn->buf.o += len;
chn->buf.p = b_ptr(&chn->buf, len);
chn->total += len;
return -1;
}
/* Tries to copy character <c> into the channel's buffer after some length
* controls. The buf->o and to_forward pointers are updated. If the channel
* controls. The chn->o and to_forward pointers are updated. If the channel
* input is closed, -2 is returned. If there is not enough room left in the
* buffer, -1 is returned. Otherwise the number of bytes copied is returned
* (1). Channel flag READ_PARTIAL is updated if some data can be transferred.
*/
int bi_putchr(struct channel *buf, char c)
int bi_putchr(struct channel *chn, char c)
{
if (unlikely(channel_input_closed(buf)))
if (unlikely(channel_input_closed(chn)))
return -2;
if (channel_full(buf))
if (channel_full(chn))
return -1;
*bi_end(&buf->buf) = c;
*bi_end(&chn->buf) = c;
buf->buf.i++;
buf->flags |= CF_READ_PARTIAL;
chn->buf.i++;
chn->flags |= CF_READ_PARTIAL;
if (buf->to_forward >= 1) {
if (buf->to_forward != CHN_INFINITE_FORWARD)
buf->to_forward--;
b_adv(&buf->buf, 1);
if (chn->to_forward >= 1) {
if (chn->to_forward != CHN_INFINITE_FORWARD)
chn->to_forward--;
b_adv(&chn->buf, 1);
}
buf->total++;
chn->total++;
return 1;
}
/* Tries to copy block <blk> at once into the channel's buffer after length
* controls. The buf->o and to_forward pointers are updated. If the channel
* controls. The chn->o and to_forward pointers are updated. If the channel
* input is closed, -2 is returned. If the block is too large for this buffer,
* -3 is returned. If there is not enough room left in the buffer, -1 is
* returned. Otherwise the number of bytes copied is returned (0 being a valid
* number). Channel flag READ_PARTIAL is updated if some data can be
* transferred.
*/
int bi_putblk(struct channel *buf, const char *blk, int len)
int bi_putblk(struct channel *chn, const char *blk, int len)
{
int max;
if (unlikely(channel_input_closed(buf)))
if (unlikely(channel_input_closed(chn)))
return -2;
max = buffer_max_len(buf);
if (unlikely(len > max - buffer_len(&buf->buf))) {
max = buffer_max_len(chn);
if (unlikely(len > max - buffer_len(&chn->buf))) {
/* we can't write this chunk right now because the buffer is
* almost full or because the block is too large. Return the
* available space or -2 if impossible.
@ -186,25 +186,25 @@ int bi_putblk(struct channel *buf, const char *blk, int len)
return 0;
/* OK so the data fits in the buffer in one or two blocks */
max = buffer_contig_space_with_res(&buf->buf, buf->buf.size - max);
memcpy(bi_end(&buf->buf), blk, MIN(len, max));
max = buffer_contig_space_with_res(&chn->buf, chn->buf.size - max);
memcpy(bi_end(&chn->buf), blk, MIN(len, max));
if (len > max)
memcpy(buf->buf.data, blk + max, len - max);
memcpy(chn->buf.data, blk + max, len - max);
buf->buf.i += len;
buf->total += len;
if (buf->to_forward) {
chn->buf.i += len;
chn->total += len;
if (chn->to_forward) {
unsigned long fwd = len;
if (buf->to_forward != CHN_INFINITE_FORWARD) {
if (fwd > buf->to_forward)
fwd = buf->to_forward;
buf->to_forward -= fwd;
if (chn->to_forward != CHN_INFINITE_FORWARD) {
if (fwd > chn->to_forward)
fwd = chn->to_forward;
chn->to_forward -= fwd;
}
b_adv(&buf->buf, fwd);
b_adv(&chn->buf, fwd);
}
/* notify that some data was read from the SI into the buffer */
buf->flags |= CF_READ_PARTIAL;
chn->flags |= CF_READ_PARTIAL;
return len;
}
@ -218,7 +218,7 @@ int bi_putblk(struct channel *buf, const char *blk, int len)
* output are full. If either of them is full, the string may be returned
* as is, without the '\n'.
*/
int bo_getline(struct channel *buf, char *str, int len)
int bo_getline(struct channel *chn, char *str, int len)
{
int ret, max;
char *p;
@ -227,16 +227,16 @@ int bo_getline(struct channel *buf, char *str, int len)
max = len;
/* closed or empty + imminent close = -1; empty = 0 */
if (unlikely((buf->flags & CF_SHUTW) || channel_is_empty(buf))) {
if (buf->flags & (CF_SHUTW|CF_SHUTW_NOW))
if (unlikely((chn->flags & CF_SHUTW) || channel_is_empty(chn))) {
if (chn->flags & (CF_SHUTW|CF_SHUTW_NOW))
ret = -1;
goto out;
}
p = bo_ptr(&buf->buf);
p = bo_ptr(&chn->buf);
if (max > buf->buf.o) {
max = buf->buf.o;
if (max > chn->buf.o) {
max = chn->buf.o;
str[max-1] = 0;
}
while (max) {
@ -246,11 +246,11 @@ int bo_getline(struct channel *buf, char *str, int len)
if (*p == '\n')
break;
p = buffer_wrap_add(&buf->buf, p + 1);
p = buffer_wrap_add(&chn->buf, p + 1);
}
if (ret > 0 && ret < len && ret < buf->buf.o &&
if (ret > 0 && ret < len && ret < chn->buf.o &&
*(str-1) != '\n' &&
!(buf->flags & (CF_SHUTW|CF_SHUTW_NOW)))
!(chn->flags & (CF_SHUTW|CF_SHUTW_NOW)))
ret = 0;
out:
if (max)
@ -266,32 +266,32 @@ int bo_getline(struct channel *buf, char *str, int len)
* The channel status is not changed. The caller must call bo_skip() to
* update it.
*/
int bo_getblk(struct channel *buf, char *blk, int len, int offset)
int bo_getblk(struct channel *chn, char *blk, int len, int offset)
{
int firstblock;
if (buf->flags & CF_SHUTW)
if (chn->flags & CF_SHUTW)
return -1;
if (len + offset > buf->buf.o) {
if (buf->flags & (CF_SHUTW|CF_SHUTW_NOW))
if (len + offset > chn->buf.o) {
if (chn->flags & (CF_SHUTW|CF_SHUTW_NOW))
return -1;
return 0;
}
firstblock = buf->buf.data + buf->buf.size - bo_ptr(&buf->buf);
firstblock = chn->buf.data + chn->buf.size - bo_ptr(&chn->buf);
if (firstblock > offset) {
if (firstblock >= len + offset) {
memcpy(blk, bo_ptr(&buf->buf) + offset, len);
memcpy(blk, bo_ptr(&chn->buf) + offset, len);
return len;
}
memcpy(blk, bo_ptr(&buf->buf) + offset, firstblock - offset);
memcpy(blk + firstblock - offset, buf->buf.data, len - firstblock + offset);
memcpy(blk, bo_ptr(&chn->buf) + offset, firstblock - offset);
memcpy(blk + firstblock - offset, chn->buf.data, len - firstblock + offset);
return len;
}
memcpy(blk, buf->buf.data + offset - firstblock, len);
memcpy(blk, chn->buf.data + offset - firstblock, len);
return len;
}