ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/dbuf.c
Revision: 1243
Committed: Fri Sep 30 10:47:53 2011 UTC (13 years, 10 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/dbuf.c
File size: 2675 byte(s)
Log Message:
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * dbuf.c: Supports dynamic data buffers.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #include "balloc.h"
28     #include "dbuf.h"
29     #include "memory.h"
30    
31     static BlockHeap *dbuf_heap;
32    
33     void
34     dbuf_init(void)
35     {
36     dbuf_heap = BlockHeapCreate("dbuf", sizeof(struct dbuf_block), DBUF_HEAP_SIZE);
37     }
38    
39     static struct dbuf_block *
40     dbuf_alloc(struct dbuf_queue *qptr)
41     {
42     struct dbuf_block *block = BlockHeapAlloc(dbuf_heap);
43    
44     dlinkAddTail(block, make_dlink_node(), &qptr->blocks);
45     return block;
46     }
47    
48     void
49     dbuf_put(struct dbuf_queue *qptr, char *data, size_t count)
50     {
51     struct dbuf_block *last;
52     size_t amount;
53    
54     assert(count > 0);
55     if (qptr->blocks.tail == NULL)
56     dbuf_alloc(qptr);
57    
58     do {
59     last = qptr->blocks.tail->data;
60    
61     amount = DBUF_BLOCK_SIZE - last->size;
62     if (!amount)
63     {
64     last = dbuf_alloc(qptr);
65     amount = DBUF_BLOCK_SIZE;
66     }
67     if (amount > count)
68     amount = count;
69    
70     memcpy((void *) &last->data[last->size], data, amount);
71     count -= amount;
72     last->size += amount;
73     qptr->total_size += amount;
74    
75     data += amount;
76    
77     } while (count > 0);
78     }
79    
80     void
81     dbuf_delete(struct dbuf_queue *qptr, size_t count)
82     {
83     dlink_node *ptr;
84     struct dbuf_block *first;
85    
86     assert(qptr->total_size >= count);
87     if (count == 0)
88     return;
89    
90     /* free whole blocks first.. */
91     while (1)
92     {
93     if (!count)
94     return;
95     ptr = qptr->blocks.head;
96     first = ptr->data;
97     if (count < first->size)
98     break;
99    
100     qptr->total_size -= first->size;
101     count -= first->size;
102     dlinkDelete(ptr, &qptr->blocks);
103     free_dlink_node(ptr);
104     BlockHeapFree(dbuf_heap, first);
105     }
106    
107     /* ..then remove data from the beginning of the queue */
108     first->size -= count;
109     qptr->total_size -= count;
110     memmove((void *) &first->data, (void *) &first->data[count], first->size);
111     }
112    

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision