本文整理汇总了C++中stream::ptr::close方法的典型用法代码示例。如果您正苦于以下问题:C++ ptr::close方法的具体用法?C++ ptr::close怎么用?C++ ptr::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream::ptr
的用法示例。
在下文中一共展示了ptr::close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copyIn
static void copyIn(IOManager *ioManager = NULL)
{
Connection conn(g_goodConnString, ioManager);
conn.execute("CREATE TEMP TABLE stuff (id INTEGER, name TEXT)");
Stream::ptr stream = conn.copyIn("stuff").csv()();
stream->write("1,cody\n");
stream->write("2,tom\n");
stream->write("3,brian\n");
stream->write("4,jeremy\n");
stream->write("5,zach\n");
stream->write("6,paul\n");
stream->write("7,alen\n");
stream->write("8,jt\n");
stream->write("9,jon\n");
stream->write("10,jacob\n");
stream->close();
Result result = conn.execute("SELECT COUNT(*) FROM stuff");
MORDOR_TEST_ASSERT_EQUAL(result.rows(), 1u);
MORDOR_TEST_ASSERT_EQUAL(result.columns(), 1u);
MORDOR_TEST_ASSERT_EQUAL(result.get<long long>(0, 0), 10);
result = conn.execute("SELECT SUM(id) FROM stuff");
MORDOR_TEST_ASSERT_EQUAL(result.rows(), 1u);
MORDOR_TEST_ASSERT_EQUAL(result.columns(), 1u);
MORDOR_TEST_ASSERT_EQUAL(result.get<long long>(0, 0), 55);
}
示例2: 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);
}
示例3: 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();
}
示例4: request
void Config::request(ServerRequest::ptr request, Access access)
{
const std::string &method = request->request().requestLine.method;
if (method == POST) {
if (access != READWRITE) {
respondError(request, FORBIDDEN);
return;
}
if (request->request().entity.contentType.type != "application" ||
request->request().entity.contentType.subtype != "x-www-form-urlencoded") {
respondError(request, UNSUPPORTED_MEDIA_TYPE);
return;
}
Stream::ptr requestStream = request->requestStream();
requestStream.reset(new LimitedStream(requestStream, 65536));
MemoryStream requestBody;
transferStream(requestStream, requestBody);
std::string queryString;
queryString.resize(requestBody.buffer().readAvailable());
requestBody.buffer().copyOut(&queryString[0], requestBody.buffer().readAvailable());
bool failed = false;
URI::QueryString qs(queryString);
for (URI::QueryString::const_iterator it = qs.begin();
it != qs.end();
++it) {
ConfigVarBase::ptr var = Mordor::Config::lookup(it->first);
if (var && !var->fromString(it->second))
failed = true;
}
if (failed) {
respondError(request, HTTP::FORBIDDEN,
"One or more new values were not accepted");
return;
}
// Fall through
}
if (method == GET || method == HEAD || method == POST) {
Format format = HTML;
URI::QueryString qs;
if (request->request().requestLine.uri.queryDefined())
qs = request->request().requestLine.uri.queryString();
URI::QueryString::const_iterator it = qs.find("alt");
if (it != qs.end() && it->second == "json")
format = JSON;
// TODO: use Accept to indicate JSON
switch (format) {
case HTML:
{
request->response().status.status = OK;
request->response().entity.contentType = MediaType("text", "html");
if (method == HEAD) {
if (request->request().requestLine.ver == Version(1, 1) &&
isAcceptable(request->request().request.te, "chunked", true)) {
request->response().general.transferEncoding.push_back("chunked");
}
return;
}
Stream::ptr response = request->responseStream();
response.reset(new BufferedStream(response));
response->write("<html><body><table>\n", 20);
Mordor::Config::visit(boost::bind(access == READWRITE ?
&eachConfigVarHTMLWrite : &eachConfigVarHTML, _1,
response));
response->write("</table></body></html>", 22);
response->close();
break;
}
case JSON:
{
JSON::Object root;
Mordor::Config::visit(boost::bind(&eachConfigVarJSON, _1, boost::ref(root)));
std::ostringstream os;
os << root;
std::string str = os.str();
request->response().status.status = OK;
request->response().entity.contentType = MediaType("application", "json");
request->response().entity.contentLength = str.size();
if (method != HEAD) {
request->responseStream()->write(str.c_str(), str.size());
request->responseStream()->close();
}
break;
}
default:
MORDOR_NOTREACHED();
}
} else {
respondError(request, METHOD_NOT_ALLOWED);
}
}
示例5: closeOnBlockingWriter
static void closeOnBlockingWriter(Stream::ptr stream, int &sequence)
{
MORDOR_TEST_ASSERT_EQUAL(++sequence, 3);
stream->close();
MORDOR_TEST_ASSERT_EQUAL(++sequence, 4);
}