本文整理汇总了C++中stream::ptr类的典型用法代码示例。如果您正苦于以下问题:C++ ptr类的具体用法?C++ ptr怎么用?C++ ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeALot
static void writeALot(Stream::ptr stream)
{
for (size_t i = 0; i < A_LOT_OF_ITERATIONS; ++i) {
MORDOR_TEST_ASSERT_EQUAL(stream->write("t", 1u), 1u);
stream->flush(false);
}
}
示例2: sslserver
MORDOR_UNITTEST(SSLStream, basic)
{
WorkerPool pool;
std::pair<Stream::ptr, Stream::ptr> pipes = pipeStream();
SSLStream::ptr sslserver(new SSLStream(pipes.first, false));
SSLStream::ptr sslclient(new SSLStream(pipes.second, true));
pool.schedule(boost::bind(&accept, sslserver));
sslclient->connect();
pool.dispatch();
Stream::ptr server = sslserver, client = sslclient;
char buf[6];
buf[5] = '\0';
client->write("hello");
client->flush(false);
MORDOR_TEST_ASSERT_EQUAL(server->read(buf, 5), 5u);
MORDOR_TEST_ASSERT_EQUAL((const char *)buf, "hello");
server->write("world");
server->flush(false);
MORDOR_TEST_ASSERT_EQUAL(client->read(buf, 5), 5u);
MORDOR_TEST_ASSERT_EQUAL((const char *)buf, "world");
}
示例3: pool
MORDOR_MAIN(int argc, const char * const argv[])
{
try {
Config::loadFromEnvironment();
StdoutStream stdoutStream;
WorkerPool pool(2);
if (argc == 1) {
argc = 2;
const char * const hyphen[] = { "", "-" };
argv = hyphen;
}
for (int i = 1; i < argc; ++i) {
Stream::ptr inStream;
std::string arg(argv[i]);
if (arg == "-") {
inStream.reset(new StdinStream());
} else {
inStream.reset(new FileStream(arg, FileStream::READ));
}
transferStream(inStream, stdoutStream);
}
} catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
}
return 0;
}
示例4: basicInFibers
static void basicInFibers(Stream::ptr stream, int &sequence)
{
MORDOR_TEST_ASSERT_EQUAL(sequence, 1);
MORDOR_TEST_ASSERT_EQUAL(stream->write("a"), 1u);
stream->close();
stream->flush();
++sequence;
MORDOR_TEST_ASSERT_EQUAL(sequence, 3);
}
示例5: eachConfigVarHTML
static void eachConfigVarHTML(ConfigVarBase::ptr var, Stream::ptr stream)
{
std::string name = var->name();
stream->write("<tr><td align=\"right\">", 22);
stream->write(name.c_str(), name.size());
stream->write("=</td><td>", 10);
std::string value = var->toString();
stream->write(value.c_str(), value.size());
stream->write("</td></tr>\n", 11);
}
示例6: cancelOnBlockingWriter
static void cancelOnBlockingWriter(Stream::ptr stream, int &sequence)
{
MORDOR_TEST_ASSERT_EQUAL(++sequence, 2);
char buffer[4096];
memset(buffer, 0, sizeof(buffer));
MORDOR_TEST_ASSERT_EXCEPTION(
while (true) stream->write(buffer, 4096),
OperationAbortedException);
MORDOR_TEST_ASSERT_EQUAL(++sequence, 4);
MORDOR_TEST_ASSERT_EXCEPTION(stream->write(buffer, 4096), OperationAbortedException);
}
示例7: BufferedStream
Connection::Connection(Stream::ptr stream)
: m_stream(stream)
{
MORDOR_ASSERT(stream);
MORDOR_ASSERT(stream->supportsRead());
MORDOR_ASSERT(stream->supportsWrite());
if (!stream->supportsUnread() || !stream->supportsFind()) {
BufferedStream *buffered = new BufferedStream(stream);
buffered->allowPartialReads(true);
m_stream.reset(buffered);
}
}
示例8: baseStream
MORDOR_UNITTEST(BufferedStream, partiallyBufferedReadRawBuffer)
{
MemoryStream::ptr baseStream(new MemoryStream("0123456789"));
BufferedStream::ptr bufferedStream(new BufferedStream(baseStream));
bufferedStream->bufferSize(3);
Stream::ptr stream = bufferedStream;
char buffer[3];
buffer[2] = '\0';
MORDOR_TEST_ASSERT_EQUAL(stream->read(buffer, 2), 2u);
MORDOR_TEST_ASSERT_EQUAL((const char *)buffer, "01");
MORDOR_TEST_ASSERT_EQUAL(stream->read(buffer, 2), 2u);
MORDOR_TEST_ASSERT_EQUAL((const char *)buffer, "23");
}
示例9: blockingWrite
static void blockingWrite(Stream::ptr stream, int &sequence)
{
MORDOR_TEST_ASSERT_EQUAL(++sequence, 3);
Buffer output;
MORDOR_TEST_ASSERT_EQUAL(stream->read(output, 10), 5u);
MORDOR_TEST_ASSERT(output == "hello");
}
示例10: while
Multipart::Multipart(Stream::ptr stream, std::string boundary)
: m_stream(stream),
m_boundary(boundary),
m_finished(false)
{
MORDOR_ASSERT(m_stream);
MORDOR_ASSERT(m_stream->supportsRead() || m_stream->supportsWrite());
MORDOR_ASSERT(!(m_stream->supportsRead() && m_stream->supportsWrite()));
while (!m_boundary.empty() && m_boundary[m_boundary.size() - 1] == ' ')
m_boundary.resize(m_boundary.size() - 1);
MORDOR_ASSERT(!m_boundary.empty());
MORDOR_ASSERT(m_boundary.size() <= 70);
if (m_boundary.find_first_not_of(allowedBoundaryChars) != std::string::npos) {
if (stream->supportsWrite()) {
MORDOR_ASSERT(false);
} else {
MORDOR_THROW_EXCEPTION(InvalidMultipartBoundaryException());
}
}
m_boundary = "\r\n--" + m_boundary;
if (m_stream->supportsRead()) {
MORDOR_ASSERT(m_stream->supportsFind());
MORDOR_ASSERT(m_stream->supportsUnread());
}
}
示例11: writeLotsaData
static void writeLotsaData(Stream::ptr stream, unsigned long long toTransfer, bool &complete)
{
RandomStream random;
MORDOR_TEST_ASSERT_EQUAL(transferStream(random, stream, toTransfer), toTransfer);
stream->flush();
complete = true;
}
示例12: eachConfigVarHTMLWrite
static void eachConfigVarHTMLWrite(ConfigVarBase::ptr var, Stream::ptr stream)
{
std::string name = var->name();
stream->write("<tr><td align=\"right\">", 22);
stream->write(name.c_str(), name.size());
stream->write("=</td><td><form name=\"", 22);
stream->write(name.c_str(), name.size());
stream->write("\" method=\"post\"><input type=\"text\" name=\"", 41);
stream->write(name.c_str(), name.size());
stream->write("\" value=\"", 9);
std::string value = var->toString();
stream->write(value.c_str(), value.size());
stream->write("\" /><input type=\"submit\" value=\"Change\" /></form></td></tr>\n", 60);
}
示例13: readWorld
static void readWorld(Stream::ptr stream, int &sequence)
{
MORDOR_TEST_ASSERT_EQUAL(++sequence, 1);
char buf[6];
buf[5] = '\0';
MORDOR_TEST_ASSERT_EQUAL(stream->read(buf, 5), 5u);
MORDOR_TEST_ASSERT_EQUAL(++sequence, 3);
MORDOR_TEST_ASSERT_EQUAL((const char *)buf, "world");
}
示例14: threadStress
void threadStress(Stream::ptr stream)
{
size_t totalRead = 0;
size_t totalWritten = 0;
size_t buf[64];
Buffer buffer;
for (int i = 0; i < 10000; ++i) {
if (i % 2) {
size_t toRead = 64;
size_t read = stream->read(buffer, toRead * sizeof(size_t));
MORDOR_TEST_ASSERT(read % sizeof(size_t) == 0);
buffer.copyOut(&buf, read);
for (size_t j = 0; read > 0; read -= sizeof(size_t), ++j) {
MORDOR_TEST_ASSERT_EQUAL(buf[j], ++totalRead);
}
buffer.clear();
} else {
size_t toWrite = 64;
for (size_t j = 0; j < toWrite; ++j) {
buf[j] = ++totalWritten;
}
buffer.copyIn(buf, toWrite * sizeof(size_t));
size_t written = stream->write(buffer, toWrite * sizeof(size_t));
totalWritten -= (toWrite - written / sizeof(size_t));
buffer.clear();
}
}
stream->close(Stream::WRITE);
while (true) {
size_t toRead = 64;
size_t read = stream->read(buffer, toRead);
if (read == 0)
break;
MORDOR_TEST_ASSERT(read % sizeof(size_t) == 0);
buffer.copyOut(&buf, read);
for (size_t i = 0; read > 0; read -= sizeof(size_t), ++i) {
MORDOR_TEST_ASSERT_EQUAL(buf[i], ++totalRead);
}
buffer.clear();
}
stream->flush();
}
示例15: baseStream
Stream::ptr
Connection::getStream(const GeneralHeaders &general,
const EntityHeaders &entity, const std::string &method, Status status,
boost::function<void()> notifyOnEof,
boost::function<void()> notifyOnException, bool forRead)
{
MORDOR_ASSERT(hasMessageBody(general, entity, method, status));
Stream::ptr stream;
if (forRead) {
stream.reset(new SingleplexStream(m_stream, SingleplexStream::READ, false));
} else {
stream.reset(new SingleplexStream(m_stream, SingleplexStream::WRITE, false));
}
Stream::ptr baseStream(stream);
for (ParameterizedList::const_reverse_iterator it(general.transferEncoding.rbegin());
it != general.transferEncoding.rend();
++it) {
if (stricmp(it->value.c_str(), "chunked") == 0) {
stream.reset(new ChunkedStream(stream));
} else if (stricmp(it->value.c_str(), "deflate") == 0) {
stream.reset(new ZlibStream(stream));
} else if (stricmp(it->value.c_str(), "gzip") == 0 ||
stricmp(it->value.c_str(), "x-gzip") == 0) {
stream.reset(new GzipStream(stream));
} else if (stricmp(it->value.c_str(), "compress") == 0 ||
stricmp(it->value.c_str(), "x-compress") == 0) {
MORDOR_ASSERT(false);
} else if (stricmp(it->value.c_str(), "identity") == 0) {
MORDOR_ASSERT(false);
} else {
MORDOR_ASSERT(false);
}
}
if (stream != baseStream) {
} else if (entity.contentLength != ~0ull) {
LimitedStream::ptr limited(new LimitedStream(stream, entity.contentLength));
limited->strict(true);
stream = limited;
} else if (entity.contentType.type == "multipart") {
// Getting stream to pass to multipart; self-delimiting
} else {
// Delimited by closing the connection
}
NotifyStream::ptr notify(new NotifyStream(stream));
stream = notify;
notify->notifyOnClose = notifyOnEof;
notify->notifyOnEof = notifyOnEof;
notify->notifyOnException = notifyOnException;
return stream;
}