本文整理汇总了C++中NPT_InputStreamReference::GetAvailable方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_InputStreamReference::GetAvailable方法的具体用法?C++ NPT_InputStreamReference::GetAvailable怎么用?C++ NPT_InputStreamReference::GetAvailable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_InputStreamReference
的用法示例。
在下文中一共展示了NPT_InputStreamReference::GetAvailable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buffer
/*----------------------------------------------------------------------
| ShowResponse
+---------------------------------------------------------------------*/
static void
ShowResponse(NPT_HttpResponse* response)
{
bool check_available = true;//true;
// show entity
NPT_HttpEntity* entity = response->GetEntity();
if (entity == NULL) return;
NPT_Console::OutputF("ENTITY: length=%lld, type=%s, encoding=%s\n",
entity->GetContentLength(),
entity->GetContentType().GetChars(),
entity->GetContentEncoding().GetChars());
NPT_DataBuffer buffer(65536);
NPT_Result result;
NPT_InputStreamReference input;
entity->GetInputStream(input);
NPT_TimeStamp start;
NPT_System::GetCurrentTimeStamp(start);
float total_read = 0.0f;
for (;;) {
NPT_Size bytes_read = 0;
NPT_LargeSize available = 0;
NPT_Size to_read = 65536;
if (check_available) {
input->GetAvailable(available);
if ((NPT_Size)available < to_read) to_read = (NPT_Size)available;
if (to_read == 0) {
to_read = 1;
NPT_TimeStamp sleep_time(0.01f);
NPT_System::Sleep(sleep_time);
}
}
result = input->Read(buffer.UseData(), to_read, &bytes_read);
if (NPT_FAILED(result)) break;
total_read += bytes_read;
NPT_TimeStamp now;
NPT_System::GetCurrentTimeStamp(now);
NPT_TimeStamp duration = now-start;
NPT_Console::OutputF("%6d avail, read %6d bytes, %6.3f KB/s\n", (int)available, bytes_read, (float)((total_read/1024.0)/(double)duration));
}
}
示例2:
/*----------------------------------------------------------------------
| NPT_HttpMessage::SetBody
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpHelper::SetBody(NPT_HttpMessage* message, NPT_InputStreamReference& stream, NPT_Size len)
{
if (len == 0) {
NPT_CHECK_SEVERE(stream->GetAvailable(len));
}
// get the entity
NPT_HttpEntity* entity = message->GetEntity();
if (entity == NULL) {
// no entity yet, create one
message->SetEntity(entity = new NPT_HttpEntity());
}
// set the entity body
entity->SetInputStream(stream);
entity->SetContentLength(len);
return NPT_SUCCESS;
}
示例3: bytes
/*----------------------------------------------------------------------
| DumpBody
+---------------------------------------------------------------------*/
static NPT_Result
ReadBody(PLT_Downloader& downloader, NPT_InputStreamReference& stream, NPT_Size& size)
{
NPT_LargeSize avail;
char buffer[2048];
NPT_Result ret = NPT_ERROR_WOULD_BLOCK;
/* reset output param first */
size = 0;
/*
we test for availability first to avoid
getting stuck in Read forever in case blocking is true
and the download is done writing to the stream
*/
NPT_CHECK(stream->GetAvailable(avail));
if (avail) {
ret = stream->Read(buffer, 2048, &size);
NPT_LOG_FINER_2("Read %d bytes (result = %d)\n", size, ret);
return ret;
} else {
Plt_DowloaderState state = downloader.GetState();
switch (state) {
case PLT_DOWNLOADER_ERROR:
return NPT_FAILURE;
case PLT_DOWNLOADER_SUCCESS:
/* no more data expected */
return NPT_ERROR_EOS;
default:
NPT_System::Sleep(NPT_TimeInterval(0, 10000));
break;
}
}
return NPT_SUCCESS;
}