本文整理汇总了C++中DataBuffer::data方法的典型用法代码示例。如果您正苦于以下问题:C++ DataBuffer::data方法的具体用法?C++ DataBuffer::data怎么用?C++ DataBuffer::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataBuffer
的用法示例。
在下文中一共展示了DataBuffer::data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_connection_data
bool NetGameConnectionImpl::read_connection_data(DataBuffer &receive_buffer, int &bytes_received)
{
while (true)
{
int bytes = connection->read(receive_buffer.data() + bytes_received, receive_buffer.size() - bytes_received);
if (bytes < 0)
return false;
if (bytes == 0)
{
connection->close();
return true;
}
bytes_received += bytes;
int bytes_consumed = 0;
bool exit = read_data(receive_buffer.data(), bytes_received, bytes_consumed);
if (bytes_consumed >= 0)
{
memmove(receive_buffer.data(), receive_buffer.data() + bytes_consumed, bytes_received - bytes_consumed);
bytes_received -= bytes_consumed;
}
if (exit)
return exit;
}
}
示例2: process
void ErrorRequestProcessor::process(HttpRequest& req, DataBuffer<uint8_t>& buffer) {
DataBuffer<char> content;
HttpStatus status;
if (code_ == EACCES) {
status = FORBIDDEN;
const std::string path = std::string("../html/403.html");
FilePro::File file(path, path);
file.content(content);
} else if (code_ == ENOENT) {
status = NOT_FOUND;
const std::string path = std::string("../html/404.html");
FilePro::File file(path, path);
file.content(content);
} else {
status = INTERNAL_ERROR;
const std::string path = std::string("../html/500.html");
FilePro::File file(path, path);
file.content(content);
}
makeHttpResponse(req, content.data(), content.size(), buffer, status);
(void)req;
}
示例3: write_connection_data
bool NetGameConnectionImpl::write_connection_data(DataBuffer &send_buffer, int &bytes_sent, bool &send_graceful_close)
{
while (true)
{
int bytes = connection->write(send_buffer.data() + bytes_sent, send_buffer.size() - bytes_sent);
if (bytes < 0)
return false;
bytes_sent += bytes;
if (bytes_sent == send_buffer.size())
{
if (send_graceful_close)
{
connection->close();
return true;
}
else
{
bytes_sent = 0;
send_buffer.set_size(0);
send_graceful_close = write_data(send_buffer);
if (send_buffer.size() == 0)
return false;
}
}
}
}
示例4: fillBufferAndQueue
bool StreamSoundSource::fillBufferAndQueue(uint buffer)
{
if(m_waitingFile)
return false;
// fill buffer
static DataBuffer<char> bufferData(2*STREAM_FRAGMENT_SIZE);
ALenum format = m_soundFile->getSampleFormat();
int maxRead = STREAM_FRAGMENT_SIZE;
if(m_downMix != NoDownMix)
maxRead *= 2;
int bytesRead = 0;
do {
bytesRead += m_soundFile->read(&bufferData[bytesRead], maxRead - bytesRead);
// end of sound file
if(bytesRead < maxRead) {
if(m_looping)
m_soundFile->reset();
else {
m_eof = true;
break;
}
}
} while(bytesRead < maxRead);
if(bytesRead > 0) {
if(m_downMix != NoDownMix) {
if(format == AL_FORMAT_STEREO16) {
assert(bytesRead % 2 == 0);
bytesRead /= 2;
uint16_t *data = (uint16_t*)bufferData.data();
for(int i=0;i<bytesRead/2;i++)
data[i] = data[2*i + (m_downMix == DownMixLeft ? 0 : 1)];
format = AL_FORMAT_MONO16;
}
}
alBufferData(buffer, format, &bufferData[0], bytesRead, m_soundFile->getRate());
ALenum err = alGetError();
if(err != AL_NO_ERROR)
g_logger.error(stdext::format("unable to refill audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err)));
alSourceQueueBuffers(m_sourceId, 1, &buffer);
err = alGetError();
if(err != AL_NO_ERROR)
g_logger.error(stdext::format("unable to queue audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err)));
}
// return false if there aren't more buffers to fill
return (bytesRead >= STREAM_FRAGMENT_SIZE && !m_eof);
}
示例5: setData
void Message::setData(DataBuffer db)
{
//kill the previous buffer
buffer.clear();
buffer.resize(db.size());
//copy the data buffer
buffer.write(db.data(), db.size());
msgHasReadLength = true;
msgLength = buffer.size();
}
示例6: write_data
bool NetGameConnectionImpl::write_data(DataBuffer &buffer)
{
std::unique_lock<std::mutex> mutex_lock(mutex);
std::vector<Message> new_send_queue;
send_queue.swap(new_send_queue);
mutex_lock.unlock();
for (auto & elem : new_send_queue)
{
if (elem.type == Message::type_message)
{
DataBufferPtr packet = NetGameNetworkData::send_data(elem.event);
int pos = buffer.size();
buffer.set_size(pos + packet->size());
memcpy(buffer.data() + pos, packet->data(), packet->size());
}
else if (elem.type == Message::type_disconnect)
{
return true;
}
}
return false;
}