File: litbuf.c

package info (click to toggle)
libhsync 0.5.7-1.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,060 kB
  • ctags: 543
  • sloc: sh: 7,944; ansic: 5,413; makefile: 154
file content (81 lines) | stat: -rw-r--r-- 2,429 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*=				       	-*- c-file-style: "bsd" -*-
 * rproxy -- dynamic caching and delta update in HTTP
 * $Id: litbuf.c,v 1.23 2000/08/10 15:16:10 mbp Exp $
 * 
 * Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* TODO: You know, queueing things up to the size of either the
 * typical TCP output buffer (32kb) or the typical packet limit (~1500
 * or ~1300) might be good.  I wonder if we can what the buffer size
 * is? */

#include "includes.h"
#include "command.h"
#include "emit.h"

/* Queue byte VALUE into the literal-data buffer. */
int
_hs_append_literal(hs_membuf_t * litbuf, byte_t value)
{
    hs_membuf_write(litbuf, &value, sizeof value);	/* LEAK HERE! */

    return 0;
}


/*
 * Write out accumulated data.  We've built up some literal or
 * signature data waiting to go out in LITBUF, and we're ready to
 * write it to WRITE_FN. CODE_BASE is either op_literal_1 or
 * op_signature_1 depending on which it is; STATS is updated
 * appropriately.
 */
ssize_t
_hs_push_literal_buf(hs_membuf_t * litbuf,
		     hs_write_fn_t write_fn, void *write_priv,
		     hs_stats_t * stats, int kind)
{
    size_t        amount;

    amount = hs_membuf_tell(litbuf);
/*      assert(amount >= 0); */

    if (amount == 0) {
	/* buffer is empty */
	return 0;
    }

    assert(kind == op_kind_literal || kind == op_kind_signature);

    if (_hs_send_literal(write_fn, write_priv, kind, litbuf->buf, amount) < 0)
	return -1;

    if (kind == op_kind_literal) {
	stats->lit_cmds++;
	stats->lit_bytes += amount;
    } else {
	assert(kind == op_kind_signature);
	stats->sig_cmds++;
	stats->sig_bytes += amount;
    }

    /* Reset the literal buffer */
    hs_membuf_truncate(litbuf);

    return 0;
}