本文整理汇总了C++中StreamBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ StreamBuffer类的具体用法?C++ StreamBuffer怎么用?C++ StreamBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StreamBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onOutput
void RpcClientImpl::onOutput(StreamBuffer& sb)
{
try
{
_exceptionPending = false;
sb.endWrite();
if (sb.out_avail() > 0)
sb.beginWrite();
else
sb.beginRead();
}
catch (const std::exception&)
{
IRemoteProcedure* proc = _proc;
cancel();
if (!proc)
throw;
_exceptionPending = true;
proc->onFinished();
if (_exceptionPending)
throw;
}
}
示例2: AUTO_LOCK
// 释放空间
void SendBuffer::Free(int32_t len)
{
if (len <= 0)
{
return;
}
AUTO_LOCK(_locker);
_buf.Free(len);
assert(!_buf.IsFull());
while (!_buf.IsFull() && !_standby_list.empty())
{
StreamBuffer<kStandbyCapacity>* standby = _standby_list.front();
int32_t move_len = 0;
const char * data = standby->Peek(move_len);
assert(data && move_len > 0);
int32_t push_len = _buf.Push(data, move_len);
assert(push_len > 0);
standby->Free(push_len);
if (standby->IsEmpty())
{
ObjectPool<StreamBuffer<kStandbyCapacity>>::Instance().Delete(standby);
_standby_list.pop_front();
}
}
}
示例3: onOutput
bool Socket::onOutput(StreamBuffer& sb)
{
log_trace("onOutput");
log_debug("send data to " << getPeerAddr());
try
{
sb.endWrite();
if ( sb.out_avail() )
{
sb.beginWrite();
}
else
{
if (sb.in_avail())
onInput(sb);
else
sb.beginRead();
}
}
catch (const std::exception& e)
{
log_warn("exception occured when processing request: " << e.what());
close();
return false;
}
return true;
}
示例4: cut
StreamBuffer StreamBuffer::cut(std::size_t size){
StreamBuffer ret;
if(m_size <= size){
ret.swap(*this);
} else {
AUTO(it, m_chunks.begin());
std::size_t total = 0; // 这是 [m_chunks.begin(), it) 的字节数,不含零头。
while(total < size){
assert(it != m_chunks.end());
const std::size_t remaining = size - total;
const std::size_t avail = it->writePos - it->readPos;
if(remaining < avail){
AUTO_REF(back, pushBackPooled(ret.m_chunks));
std::memcpy(back.data, it->data + it->readPos, remaining);
back.writePos = remaining;
it->readPos += remaining;
ret.m_size += remaining;
m_size -= remaining;
break;
}
total += avail;
++it;
}
ret.m_chunks.splice(ret.m_chunks.begin(), m_chunks, m_chunks.begin(), it);
ret.m_size += total;
m_size -= total;
}
return ret;
}
示例5: CutOff
StreamBuffer StreamBuffer::CutOff(std::size_t uSize){
StreamBuffer sbufRet;
if(x_uSize <= uSize){
sbufRet.Swap(*this);
} else {
auto pNode = x_lstBuffers.GetFirst();
std::size_t uTotal = 0; // 这是 [x_lstBuffers.GetFirst(), pNode) 的字节数,不含零头。
while(uTotal < uSize){
ASSERT(pNode);
auto &vBuffer = pNode->Get();
const std::size_t uRemaining = uSize - uTotal;
const auto uAvail = vBuffer.m_uWrite - vBuffer.m_uRead;
if(uRemaining < uAvail){
auto &vNewBuffer = xChunk::PushPooled(sbufRet.x_lstBuffers);
vNewBuffer.m_uRead = 0;
vNewBuffer.m_uWrite = uRemaining;
std::memcpy(vNewBuffer.m_abyData, vBuffer.m_abyData + vBuffer.m_uRead, uRemaining);
vBuffer.m_uRead += uRemaining;
sbufRet.x_uSize += uRemaining;
x_uSize -= uRemaining;
break;
}
uTotal += uAvail;
pNode = pNode->GetNext();
}
sbufRet.x_lstBuffers.Splice(sbufRet.x_lstBuffers.GetFirst(),
x_lstBuffers, x_lstBuffers.GetFirst(), pNode);
sbufRet.x_uSize += uTotal;
x_uSize -= uTotal;
}
return sbufRet;
}
示例6: writeBitsImpl
void writeBitsImpl(DataType value, int bitCount,
StreamBuffer& streamBuffer, int& holdingBitCount, int& totalBitCount)
{
assert(isEnoughBits<DataType>(bitCount));
if (! isEnoughBits<DataType>(bitCount)) {
throw StreamingException(__FILE__, __LINE__, "invalid bitCount");
}
DataType theValue = resetUnusedBits(value, bitCount);
if (holdingBitCount > 0) {
if (streamBuffer.empty()) {
throw StreamingException(__FILE__, __LINE__, "buffer is empty");
}
streamBuffer.back() |= UInt8(theValue << holdingBitCount);
}
else {
streamBuffer.push(UInt8(theValue));
}
const int bitShiftCount = CHAR_BIT - holdingBitCount;
if (bitCount > bitShiftCount) {
int leftBitCount = bitCount - bitShiftCount;
theValue >>= bitShiftCount;
do {
streamBuffer.push(UInt8(theValue));
theValue >>= CHAR_BIT;
leftBitCount -= CHAR_BIT;
}
while (leftBitCount > 0);
}
示例7: unmarshall
proto::message
unmarshall(StreamBuffer& buff)
{
buff.set_mark();
auto result = proto::deserialize<proto::binary_message_deserializer>(buff);
buff.unset_mark();
return result;
}
示例8:
std::ostream &
operator<< (std::ostream &out, const SetFile manip)
{
StreamBuffer *buf = dynamic_cast<StreamBuffer *> (out.rdbuf ());
if (buf)
buf->SetFile (manip.file);
return out;
}
示例9: cut_off
StreamBuffer StreamBuffer::cut_off(std::size_t bytes){
StreamBuffer ret;
const AUTO(bytes_to_copy, std::min(bytes, m_size));
if(bytes_to_copy == 0){
return ret;
}
if(m_size <= bytes_to_copy){
ret.swap(*this);
return ret;
}
std::size_t bytes_copied = 0;
AUTO(cut_end, m_first);
for(;;){
const AUTO(bytes_remaining, bytes_to_copy - bytes_copied);
const AUTO(bytes_avail, cut_end->end - cut_end->begin);
if(bytes_remaining <= bytes_avail){
if(bytes_remaining == bytes_avail){
cut_end = cut_end->next;
} else {
const AUTO(chunk, new Chunk);
chunk->next = cut_end;
chunk->prev = cut_end->prev;
chunk->begin = 0;
chunk->end = bytes_remaining;
std::memcpy(chunk->data, cut_end->data + cut_end->begin, bytes_remaining);
cut_end->begin += bytes_remaining;
if(cut_end->prev){
cut_end->prev->next = chunk;
} else {
m_first = chunk;
}
cut_end->prev = chunk;
}
break;
}
bytes_copied += bytes_avail;
cut_end = cut_end->next;
}
const AUTO(cut_first, m_first);
const AUTO(cut_last, cut_end->prev);
cut_last->next = NULLPTR;
cut_end->prev = NULLPTR;
m_first = cut_end;
m_size -= bytes_to_copy;
ret.m_first = cut_first;
ret.m_last = cut_last;
ret.m_size = bytes_to_copy;
return ret;
}
示例10: serialize
void URLTable::serialize( StreamBuffer &stream ) {
for ( std::map<int, string>::iterator it = map.begin(); it!=map.end(); ++it){
stream.write(&it->first);
int tmp = it->second.length();
stream.write(&tmp);
stream.write(it->second.c_str(), it->second.length());
}
}
示例11: ReadData
void Stream::ReadData(const StreamBuffer& value)
{
if (streamMode == SmMemory)
{
unsigned int size = std::max(static_cast<int>(value.size()), static_cast<int>(value.size() - buffer.size()));
std::memcpy((void*)value.data(), buffer.data() + position, size);
position += value.size();
}
else
fileStream.read(reinterpret_cast<char*>(const_cast<unsigned char*>(value.data())), value.size());
}
示例12: serialize
void WordMap::serialize( StreamBuffer &stream )
{
for ( std::map<string, int>::iterator it = map.begin(); it!=map.end(); ++it)
{
int tmp = it->first.length();
stream.write(&tmp);
stream.write(it->first.c_str(), it->first.length());
stream.write(&it->second);
}
}
示例13: while
std::ostream &
operator<< (std::ostream &out, const LockType)
{
StreamBuffer *buf = dynamic_cast<StreamBuffer *> (out.rdbuf ());
if (buf)
{
while (buf->IsLocked ()); // Loop infinitely until we can lock.
buf->Lock ();
}
return out;
}
示例14: onInput
void ClientImpl::onInput(StreamBuffer& sb)
{
try
{
try
{
log_trace("ClientImpl::onInput; readHeader=" << _readHeader);
_errorPending = false;
sb.endRead();
if (sb.device()->eof())
throw IOError("end of input");
_reconnectOnError = false;
if (_readHeader)
{
processHeaderAvailable(sb);
}
else
{
processBodyAvailable(sb);
}
}
catch (const IOError& e)
{
// after writing the request, the first read request may
// detect, that the server has already closed the connection,
// so check it here
if (_readHeader && _reconnectOnError && _request != 0)
{
log_debug("reconnect on error");
_socket.close();
_reconnectOnError = false;
reexecuteBegin(*_request);
return;
}
throw;
}
}
catch (const std::exception& e)
{
_errorPending = true;
_client->replyFinished(*_client);
if (_errorPending)
throw;
}
}
示例15: onOutput
bool Socket::onOutput(StreamBuffer& sb)
{
log_trace("onOutput");
log_debug("send data to " << getPeerAddr());
try
{
sb.endWrite();
if ( sb.out_avail() )
{
sb.beginWrite();
_timer.start(_server.writeTimeout());
}
else
{
bool keepAlive = _request.header().keepAlive()
&& _reply.header().keepAlive();
if (keepAlive)
{
log_debug("do keep alive");
_timer.start(_server.keepAliveTimeout());
_request.clear();
_reply.clear();
_parser.reset(false);
if (sb.in_avail())
onInput(sb);
else
_stream.buffer().beginRead();
}
else
{
log_debug("don't do keep alive");
close();
return false;
}
}
}
catch (const std::exception& e)
{
log_warn("exception occured when processing request: " << e.what());
close();
timeout(*this);
return false;
}
return true;
}