aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/llpipeutil.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/test/llpipeutil.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/test/llpipeutil.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/linden/indra/test/llpipeutil.cpp b/linden/indra/test/llpipeutil.cpp
new file mode 100644
index 0000000..53c5991
--- /dev/null
+++ b/linden/indra/test/llpipeutil.cpp
@@ -0,0 +1,158 @@
1/**
2 * @file llpipeutil.cpp
3 * @date 2006-05-18
4 * @brief Utility pipe fittings for injecting and extracting strings
5 *
6 * Copyright (c) 2006-2007, Linden Research, Inc.
7 *
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29#include "llpipeutil.h"
30
31#include <stdlib.h>
32
33#include "llbufferstream.h"
34#include "llframetimer.h"
35#include "llpumpio.h"
36#include "llrand.h"
37#include "lltimer.h"
38
39F32 pump_loop(LLPumpIO* pump, F32 seconds)
40{
41 LLTimer timer;
42 timer.setTimerExpirySec(seconds);
43 while(!timer.hasExpired())
44 {
45 LLFrameTimer::updateFrameTime();
46 pump->pump();
47 pump->callback();
48 }
49 return timer.getElapsedTimeF32();
50}
51
52//virtual
53LLIOPipe::EStatus LLPipeStringInjector::process_impl(
54 const LLChannelDescriptors& channels,
55 buffer_ptr_t& buffer,
56 bool& eos,
57 LLSD& context,
58 LLPumpIO* pump)
59{
60 buffer->append(channels.out(), (U8*) mString.data(), mString.size());
61 eos = true;
62 return STATUS_DONE;
63}
64
65
66LLIOPipe::EStatus LLPipeStringExtractor::process_impl(
67 const LLChannelDescriptors& channels,
68 buffer_ptr_t& buffer,
69 bool& eos,
70 LLSD& context,
71 LLPumpIO* pump)
72{
73 if(!eos) return STATUS_BREAK;
74 if(!pump || !buffer) return STATUS_PRECONDITION_NOT_MET;
75
76 LLBufferStream istr(channels, buffer.get());
77 std::ostringstream ostr;
78 while (istr.good())
79 {
80 char buf[1024];
81 istr.read(buf, sizeof(buf));
82 ostr.write(buf, istr.gcount());
83 }
84 mString = ostr.str();
85 mDone = true;
86
87 return STATUS_DONE;
88}
89
90
91// virtual
92LLIOPipe::EStatus LLIOFuzz::process_impl(
93 const LLChannelDescriptors& channels,
94 buffer_ptr_t& buffer,
95 bool& eos,
96 LLSD& context,
97 LLPumpIO* pump)
98{
99 while(mByteCount)
100 {
101 std::vector<U8> data;
102 data.reserve(10000);
103 int size = llmin(10000, mByteCount);
104 std::generate_n(
105 std::back_insert_iterator< std::vector<U8> >(data),
106 size,
107 rand);
108 buffer->append(channels.out(), &data[0], size);
109 mByteCount -= size;
110 }
111 return STATUS_OK;
112}
113
114struct random_ascii_generator
115{
116 random_ascii_generator() {}
117 U8 operator()()
118 {
119 int rv = rand();
120 rv %= (127 - 32);
121 rv += 32;
122 return rv;
123 }
124};
125
126// virtual
127LLIOPipe::EStatus LLIOASCIIFuzz::process_impl(
128 const LLChannelDescriptors& channels,
129 buffer_ptr_t& buffer,
130 bool& eos,
131 LLSD& context,
132 LLPumpIO* pump)
133{
134 while(mByteCount)
135 {
136 std::vector<U8> data;
137 data.reserve(10000);
138 int size = llmin(10000, mByteCount);
139 std::generate_n(
140 std::back_insert_iterator< std::vector<U8> >(data),
141 size,
142 random_ascii_generator());
143 buffer->append(channels.out(), &data[0], size);
144 mByteCount -= size;
145 }
146 return STATUS_OK;
147}
148
149// virtual
150LLIOPipe::EStatus LLIONull::process_impl(
151 const LLChannelDescriptors& channels,
152 buffer_ptr_t& buffer,
153 bool& eos,
154 LLSD& context,
155 LLPumpIO* pump)
156{
157 return STATUS_OK;
158}