本文整理汇总了C++中CharBuffer::Reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ CharBuffer::Reserve方法的具体用法?C++ CharBuffer::Reserve怎么用?C++ CharBuffer::Reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharBuffer
的用法示例。
在下文中一共展示了CharBuffer::Reserve方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFileIntoBuffer
bool FileSystem::LoadFileIntoBuffer(const char* filename, CharBuffer& buffer, bool addTrailingNull)
{
DiskFile file;
if (!file.Open(filename, DiskFile::omRead))
{
return false;
}
// obtain file size.
file.Seek(0, DiskFile::soEnd);
int size = (int)file.Position();
file.Seek(0);
// allocate memory to contain the whole file.
buffer.Reserve(size + (addTrailingNull ? 1 : 0));
// copy the file into the buffer.
file.Read(buffer, size);
file.Close();
if (addTrailingNull)
{
buffer[size] = 0;
}
return true;
}
示例2: SendBodyResponse
void WebProcessor::SendBodyResponse(const char* body, int bodyLen, const char* contentType)
{
const char* RESPONSE_HEADER =
"HTTP/1.1 200 OK\r\n"
"Connection: close\r\n"
"Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n"
"Access-Control-Allow-Origin: %s\r\n"
"Access-Control-Allow-Credentials: true\r\n"
"Access-Control-Max-Age: 86400\r\n"
"Access-Control-Allow-Headers: Content-Type, Authorization\r\n"
"X-Auth-Token: %s\r\n"
"Content-Length: %i\r\n"
"%s" // Content-Type: xxx
"%s" // Content-Encoding: gzip
"Server: nzbget-%s\r\n"
"\r\n";
#ifndef DISABLE_GZIP
CharBuffer gbuf;
bool gzip = m_gzip && bodyLen > MAX_UNCOMPRESSED_SIZE;
if (gzip)
{
uint32 outLen = ZLib::GZipLen(bodyLen);
gbuf.Reserve(outLen);
int gzippedLen = ZLib::GZip(body, bodyLen, *gbuf, outLen);
if (gzippedLen > 0 && gzippedLen < bodyLen)
{
body = gbuf;
bodyLen = gzippedLen;
}
else
{
gzip = false;
}
}
#else
bool gzip = false;
#endif
BString<1024> contentTypeHeader;
if (contentType)
{
contentTypeHeader.Format("Content-Type: %s\r\n", contentType);
}
BString<1024> responseHeader(RESPONSE_HEADER,
m_origin.Str(),
m_serverAuthToken[m_userAccess], bodyLen, *contentTypeHeader,
gzip ? "Content-Encoding: gzip\r\n" : "",
Util::VersionRevision());
// Send the request answer
m_connection->Send(responseHeader, responseHeader.Length());
m_connection->Send(body, bodyLen);
}
示例3: GetMyProgramFile
PathName SessionImpl::GetMyProgramFile(bool canonicalized)
{
// we do this once
if (myProgramFile.Empty())
{
#if defined(__APPLE__)
CharBuffer<char> buf;
uint32_t bufsize = buf.GetCapacity();
if (_NSGetExecutablePath(buf.GetData(), &bufsize) < 0)
{
buf.Reserve(bufsize);
if (_NSGetExecutablePath(buf.GetData(), &bufsize) != 0)
{
MIKTEX_UNEXPECTED();
}
}
myProgramFile = buf.GetData();
#else
string invocationName = initInfo.GetProgramInvocationName();
if (invocationName.empty())
{
MIKTEX_FATAL_ERROR(T_("No invocation name has been set."));
}
if (Utils::IsAbsolutePath(invocationName.c_str()))
{
myProgramFile = invocationName;
}
else if (invocationName.length() > 3 && (invocationName.substr(0, 2) == "./" || invocationName.substr(0, 3) == "../"))
{
myProgramFile = GetFullPath(invocationName.c_str());
}
else if (!Utils::FindProgram(invocationName, myProgramFile))
{
MIKTEX_FATAL_ERROR_2(T_("The invoked program could not be found in the PATH."), "invocationName", invocationName);
}
#endif
myProgramFileCanon = myProgramFile;
myProgramFileCanon.Canonicalize();
}
if (canonicalized)
{
return myProgramFileCanon;
}
else
{
return myProgramFile;
}
}
示例4:
bool RarVolume::ReadRar3File(DiskFile& file, RarBlock& block, RarFile& innerFile)
{
innerFile.m_splitBefore = block.flags & RAR3_FILE_SPLITBEFORE;
innerFile.m_splitAfter = block.flags & RAR3_FILE_SPLITAFTER;
uint16 namelen;
uint32 size;
if (!Read32(file, &block, &size)) return false;
innerFile.m_size = size;
if (!Skip(file, &block, 1)) return false;
if (!Skip(file, &block, 4)) return false;
if (!Read32(file, &block, &innerFile.m_time)) return false;
if (!Skip(file, &block, 2)) return false;
if (!Read16(file, &block, &namelen)) return false;
if (!Read32(file, &block, &innerFile.m_attr)) return false;
if (block.flags & RAR3_FILE_ADDSIZE)
{
uint32 highsize;
if (!Read32(file, &block, &highsize)) return false;
block.trailsize += (uint64)highsize << 32;
if (!Read32(file, &block, &highsize)) return false;
innerFile.m_size += (uint64)highsize << 32;
}
if (namelen > 8192) return false; // an error
CharBuffer name;
name.Reserve(namelen + 1);
if (!Read(file, &block, (char*)name, namelen)) return false;
name[namelen] = '\0';
innerFile.m_filename = name;
debug("%i, %i, %s", (int)block.trailsize, (int)namelen, (const char*)name);
return true;
}
示例5: RequestFileList
bool Frontend::RequestFileList()
{
const char* controlIp = !strcmp(g_Options->GetControlIp(), "0.0.0.0") ? "127.0.0.1" : g_Options->GetControlIp();
Connection connection(controlIp, g_Options->GetControlPort(), false);
bool OK = connection.Connect();
if (!OK)
{
return false;
}
SNzbListRequest ListRequest;
InitMessageBase(&ListRequest.m_messageBase, rrList, sizeof(ListRequest));
ListRequest.m_fileList = htonl(m_fileList);
ListRequest.m_serverState = htonl(m_summary);
if (!connection.Send((char*)(&ListRequest), sizeof(ListRequest)))
{
return false;
}
// Now listen for the returned list
SNzbListResponse ListResponse;
bool read = connection.Recv((char*) &ListResponse, sizeof(ListResponse));
if (!read ||
(int)ntohl(ListResponse.m_messageBase.m_signature) != (int)NZBMESSAGE_SIGNATURE ||
ntohl(ListResponse.m_messageBase.m_structSize) != sizeof(ListResponse))
{
return false;
}
CharBuffer buf;
if (ntohl(ListResponse.m_trailingDataLength) > 0)
{
buf.Reserve(ntohl(ListResponse.m_trailingDataLength));
if (!connection.Recv(buf, buf.Size()))
{
return false;
}
}
connection.Disconnect();
if (m_summary)
{
m_pauseDownload = ntohl(ListResponse.m_downloadPaused);
m_remainingSize = Util::JoinInt64(ntohl(ListResponse.m_remainingSizeHi), ntohl(ListResponse.m_remainingSizeLo));
m_currentDownloadSpeed = ntohl(ListResponse.m_downloadRate);
m_downloadLimit = ntohl(ListResponse.m_downloadLimit);
m_threadCount = ntohl(ListResponse.m_threadCount);
m_postJobCount = ntohl(ListResponse.m_postJobCount);
m_upTimeSec = ntohl(ListResponse.m_upTimeSec);
m_dnTimeSec = ntohl(ListResponse.m_downloadTimeSec);
m_standBy = ntohl(ListResponse.m_downloadStandBy);
m_allBytes = Util::JoinInt64(ntohl(ListResponse.m_downloadedBytesHi), ntohl(ListResponse.m_downloadedBytesLo));
}
if (m_fileList && ntohl(ListResponse.m_trailingDataLength) > 0)
{
RemoteClient client;
client.SetVerbose(false);
client.BuildFileList(&ListResponse, buf, DownloadQueue::Guard());
}
return true;
}
示例6: RequestMessages
bool Frontend::RequestMessages()
{
const char* controlIp = !strcmp(g_Options->GetControlIp(), "0.0.0.0") ? "127.0.0.1" : g_Options->GetControlIp();
Connection connection(controlIp, g_Options->GetControlPort(), false);
bool OK = connection.Connect();
if (!OK)
{
return false;
}
SNzbLogRequest LogRequest;
InitMessageBase(&LogRequest.m_messageBase, rrLog, sizeof(LogRequest));
LogRequest.m_lines = htonl(m_neededLogEntries);
if (m_neededLogEntries == 0)
{
LogRequest.m_idFrom = htonl(m_neededLogFirstId > 0 ? m_neededLogFirstId : 1);
}
else
{
LogRequest.m_idFrom = 0;
}
if (!connection.Send((char*)(&LogRequest), sizeof(LogRequest)))
{
return false;
}
// Now listen for the returned log
SNzbLogResponse LogResponse;
bool read = connection.Recv((char*) &LogResponse, sizeof(LogResponse));
if (!read ||
(int)ntohl(LogResponse.m_messageBase.m_signature) != (int)NZBMESSAGE_SIGNATURE ||
ntohl(LogResponse.m_messageBase.m_structSize) != sizeof(LogResponse))
{
return false;
}
CharBuffer buf;
if (ntohl(LogResponse.m_trailingDataLength) > 0)
{
buf.Reserve(ntohl(LogResponse.m_trailingDataLength));
if (!connection.Recv(buf, buf.Size()))
{
return false;
}
}
connection.Disconnect();
if (ntohl(LogResponse.m_trailingDataLength) > 0)
{
char* bufPtr = (char*)buf;
for (uint32 i = 0; i < ntohl(LogResponse.m_nrTrailingEntries); i++)
{
SNzbLogResponseEntry* logAnswer = (SNzbLogResponseEntry*) bufPtr;
char* text = bufPtr + sizeof(SNzbLogResponseEntry);
m_remoteMessages.emplace_back(ntohl(logAnswer->m_id), (Message::EKind)ntohl(logAnswer->m_kind), ntohl(logAnswer->m_time), text);
bufPtr += sizeof(SNzbLogResponseEntry) + ntohl(logAnswer->m_textLen);
}
}
return true;
}
示例7: tmp
void
TarExtractor::Extract (/*[in]*/ Stream * pStreamIn_,
/*[in]*/ const PathName & destDir,
/*[in]*/ bool makeDirectories,
/*[in]*/ IExtractCallback * pCallback,
/*[in]*/ const char * lpszPrefix)
{
try
{
pStreamIn = pStreamIn_;
totalBytesRead = 0;
traceStream->WriteFormattedLine ("libextractor",
T_("extracting to %s (%s)"),
Q_(destDir),
(makeDirectories
? T_("make directories")
: T_("don't make directories")));
size_t len;
Header header;
size_t prefixLen = (lpszPrefix == 0 ? 0 : StrLen(lpszPrefix));
unsigned fileCount = 0;
bool checkHeader = true;
CharBuffer<char> buffer;
buffer.Reserve (1024 * 1024);
while ((len = Read(&header, sizeof(header))) > 0)
{
// read next header
if (len != sizeof(header))
{
FATAL_EXTRACTOR_ERROR
("TarExtractor::Extract",
T_("Invalid package archive file."),
0);
}
if (header.IsEndOfArchive())
{
break;
}
if (checkHeader)
{
if (! header.Check())
{
FATAL_EXTRACTOR_ERROR
("TarExtractor::Extract",
T_("Invalid package archive file."),
0);
}
#if ! defined(MIKTEX_DEBUG)
checkHeader = false;
#endif
}
PathName dest = header.GetFileName();
size_t size = header.GetFileSize();
if (! header.IsNormalFile())
{
if (header.GetType() == Header::LongName)
{
if (size >= BLOCKSIZE)
{
UNEXPECTED_CONDITION ("TarExtractor::Extract");
}
char longNameData[BLOCKSIZE];
ReadBlock (longNameData);
longNameData[size] = 0;
longName = longNameData;
haveLongName = true;
}
else
{
Skip (((size + sizeof(Header) - 1) / sizeof(Header))
* sizeof(Header));
}
continue;
}
if (haveLongName)
{
dest = longName;
haveLongName = false;
}
// skip directory prefix
if (lpszPrefix != 0
&& PathName::Compare(lpszPrefix, dest, prefixLen) == 0)
{
PathName tmp (dest);
dest = tmp.Get() + prefixLen;
}
// make the destination path name
PathName path (destDir);
//.........这里部分代码省略.........
示例8: CompleteFileParts
//.........这里部分代码省略.........
}
tmpdestfile = *m_outputFilename;
}
else if (g_Options->GetRawArticle())
{
FileSystem::DeleteFile(tmpdestfile);
if (!FileSystem::CreateDirectory(ofn))
{
m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
"Could not create directory %s: %s", *ofn, *FileSystem::GetLastErrorMessage());
return;
}
}
if (outfile.Active())
{
SetWriteBuffer(outfile, 0);
}
uint32 crc = 0;
{
std::unique_ptr<ArticleCache::FlushGuard> flushGuard;
if (cached)
{
flushGuard = std::make_unique<ArticleCache::FlushGuard>(g_ArticleCache->GuardFlush());
}
CharBuffer buffer;
bool firstArticle = true;
if (!g_Options->GetRawArticle() && !directWrite)
{
buffer.Reserve(1024 * 64);
}
for (ArticleInfo* pa : m_fileInfo->GetArticles())
{
if (pa->GetStatus() != ArticleInfo::aiFinished)
{
continue;
}
if (!g_Options->GetRawArticle() && !directWrite && pa->GetSegmentOffset() > -1 &&
pa->GetSegmentOffset() > outfile.Position() && outfile.Position() > -1)
{
memset(buffer, 0, buffer.Size());
if (!g_Options->GetSkipWrite())
{
while (pa->GetSegmentOffset() > outfile.Position() && outfile.Position() > -1 &&
outfile.Write(buffer, std::min((int)(pa->GetSegmentOffset() - outfile.Position()), buffer.Size())));
}
}
if (pa->GetSegmentContent())
{
if (!g_Options->GetSkipWrite())
{
outfile.Seek(pa->GetSegmentOffset());
outfile.Write(pa->GetSegmentContent(), pa->GetSegmentSize());
}
pa->DiscardSegment();
}
else if (!g_Options->GetRawArticle() && !directWrite && !g_Options->GetSkipWrite())
{
DiskFile infile;