本文整理汇总了C++中ostream::setstate方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::setstate方法的具体用法?C++ ostream::setstate怎么用?C++ ostream::setstate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ostream
的用法示例。
在下文中一共展示了ostream::setstate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: streamData
//.........这里部分代码省略.........
// Even if we are at the end of the buffer, or within range. If we are filtering,
// we will need to make sure we are not spinning when there are no valid events
// to be reported. we will waste cycles spinning on the end of the buffer when
// we should be in a heartbeat wait as well.
if (!endOfBuffer) {
// If we're not at the end of the buffer, move to the end of the previous set and
// begin filtering from where we left off.
start = end;
// For replaying of events, we will stream as fast as we can with a 1ms sleep
// to allow other threads to run.
dlib::sleep(1);
} else {
uint64 delta;
if (!current) {
// Busy wait to make sure the signal was actually signaled. We have observed that
// a signal can occur in rare conditions where there are multiple threads listening
// on separate condition variables and this pops out too soon. This will make sure
// observer was actually signaled and instead of throwing an error will wait again
// for the remaining hartbeat interval.
delta = (ts.get_timestamp() - last) / 1000;
while (delta < aHeartbeat &&
observer.wait(aHeartbeat - delta) &&
!observer.wasSignaled()) {
delta = (ts.get_timestamp() - last) / 1000;
}
{
dlib::auto_mutex lock(*mSequenceLock);
// Make sure the observer was signaled!
if (!observer.wasSignaled()) {
// If nothing came out during the last wait, we may have still have advanced
// the sequence number. We should reset the start to something closer to the
// current sequence. If we lock the sequence lock, we can check if the observer
// was signaled between the time the wait timed out and the mutex was locked.
// Otherwise, nothing has arrived and we set to the next sequence number to
// the next sequence number to be allocated and continue.
start = mSequence;
} else {
// Get the sequence # signaled in the observer when the earliest event arrived.
// This will allow the next set of data to be pulled. Any later events will have
// greater sequence numbers, so this should not cause a problem. Also, signaled
// sequence numbers can only decrease, never increase.
start = observer.getSequence();
}
}
}
// Now wait the remainder if we triggered before the timer was up.
delta = ts.get_timestamp() - last;
if (delta < interMicros) {
// Sleep the remainder
dlib::sleep((interMicros - delta) / 1000);
}
}
}
}
catch (ParameterError &aError)
{
sLogger << LINFO << "Caught a parameter error.";
if (out.good()) {
ostringstream str;
string content = printError(aError.mCode, aError.mMessage);
str << "--" << boundary << "\r\n"
"Content-type: text/xml\r\n"
"Content-length: " << content.length() << "\r\n\r\n"
<< content;
string chunk = str.str();
out.setf(ios::hex, ios::basefield);
out << chunk.length() << "\r\n";
out << chunk << "\r\n";
out.flush();
}
}
catch (...)
{
sLogger << LWARN << "Error occurred during streaming data";
if (out.good()) {
ostringstream str;
string content = printError("INTERNAL_ERROR", "Unknown error occurred during streaming");
str << "--" << boundary << "\r\n"
"Content-type: text/xml\r\n"
"Content-length: " << content.length() << "\r\n\r\n"
<< content;
string chunk = str.str();
out.setf(ios::hex, ios::basefield);
out << chunk.length() << "\r\n";
out << chunk;
out.flush();
}
}
out.setstate(ios::badbit);
// Observer is auto removed from signalers
}