monotone

monotone Mtn Source Tree

Root/botan/out_buf.cpp

1/*************************************************
2* Pipe Output Buffer Source file *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/out_buf.h>
7#include <botan/secqueue.h>
8
9namespace Botan {
10
11/*************************************************
12* Read data from a message *
13*************************************************/
14u32bit Output_Buffers::read(byte output[], u32bit length, u32bit msg)
15 {
16 SecureQueue* q = get(msg);
17 if(q)
18 return q->read(output, length);
19 return 0;
20 }
21
22/*************************************************
23* Peek at data in a message *
24*************************************************/
25u32bit Output_Buffers::peek(byte output[], u32bit length,
26 u32bit stream_offset, u32bit msg) const
27 {
28 SecureQueue* q = get(msg);
29 if(q)
30 return q->peek(output, length, stream_offset);
31 return 0;
32 }
33
34/*************************************************
35* Check available bytes in a message *
36*************************************************/
37u32bit Output_Buffers::remaining(u32bit msg) const
38 {
39 SecureQueue* q = get(msg);
40 if(q)
41 return q->size();
42 return 0;
43 }
44
45/*************************************************
46* Add a new output queue *
47*************************************************/
48void Output_Buffers::add(SecureQueue* queue)
49 {
50 if(!queue)
51 throw Internal_Error("Output_Buffers::add: Argument was NULL");
52
53 if(buffers.size() == buffers.max_size())
54 throw Internal_Error("Output_Buffers::add: No more room in container");
55
56 buffers.push_back(queue);
57 }
58
59/*************************************************
60* Retire old output queues *
61*************************************************/
62void Output_Buffers::retire()
63 {
64 while(buffers.size())
65 {
66 if(buffers[0] == 0 || buffers[0]->size() == 0)
67 {
68 delete buffers[0];
69 buffers.pop_front();
70 ++offset;
71 }
72 else
73 break;
74 }
75 }
76
77/*************************************************
78* Get a particular output queue *
79*************************************************/
80SecureQueue* Output_Buffers::get(u32bit msg) const
81 {
82 if(msg < offset)
83 return 0;
84 if(msg > message_count())
85 throw Internal_Error("Output_Buffers::get: msg > size");
86
87 return buffers[msg-offset];
88 }
89
90/*************************************************
91* Return the total number of messages *
92*************************************************/
93u32bit Output_Buffers::message_count() const
94 {
95 return (buffers.size() + offset);
96 }
97
98/*************************************************
99* Output_Buffers Constructor *
100*************************************************/
101Output_Buffers::Output_Buffers()
102 {
103 offset = 0;
104 }
105
106/*************************************************
107* Output_Buffers Destructor *
108*************************************************/
109Output_Buffers::~Output_Buffers()
110 {
111 for(u32bit j = 0; j != buffers.size(); ++j)
112 delete buffers[j];
113 }
114
115}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status