本文整理汇总了C++中ds::String::length方法的典型用法代码示例。如果您正苦于以下问题:C++ String::length方法的具体用法?C++ String::length怎么用?C++ String::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ds::String
的用法示例。
在下文中一共展示了String::length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dm_htserv
void dm_htserv()
{
printf("[Status] Running on %s\n", DS::SockIpAddress(s_listenSock).c_str());
try {
for ( ;; ) {
DS::SocketHandle client;
try {
client = DS::AcceptSock(s_listenSock);
} catch (DS::SockHup) {
break;
}
if (!client)
continue;
std::list<DS::String> lines;
for ( ;; ) {
std::unique_ptr<char[]> buffer;
DS::String scratch;
try {
size_t bufSize = DS::PeekSize(client);
buffer.reset(new char[scratch.length() + bufSize + 1]);
memcpy(buffer.get(), scratch.c_str(), scratch.length());
DS::RecvBuffer(client, buffer.get() + scratch.length(), bufSize);
buffer[scratch.length() + bufSize] = 0;
} catch (const DS::SockHup&) {
lines.clear();
break;
}
char* cp = buffer.get();
char* sp = buffer.get();
while (*cp) {
if (*cp == '\r' || *cp == '\n') {
if (*cp == '\r' && *(cp + 1) == '\n') {
// Delete both chars of the Windows newline
*cp++ = 0;
}
*cp++ = 0;
lines.push_back(DS::String(sp));
sp = cp;
scratch = "";
} else {
++cp;
}
}
if (cp != sp)
scratch += sp;
if (lines.size() && lines.back().isEmpty()) {
// Got the separator line
break;
}
}
if (lines.empty()) {
DS::FreeSock(client);
continue;
}
// First line contains the action
std::vector<DS::String> action = lines.front().split();
if (action.size() < 2) {
fprintf(stderr, "[Status] Incorrectly formatted HTTP request: %s\n",
lines.front().c_str());
DS::FreeSock(client);
continue;
}
if (action[0] != "GET") {
fprintf(stderr, "[Status] Unsupported method: %s\n", action[0].c_str());
DS::FreeSock(client);
continue;
}
if (action.size() < 3 || action[2] != "HTTP/1.1") {
fputs("[Status] Unsupported HTTP Version\n", stderr);
DS::FreeSock(client);
continue;
}
DS::String path = action[1];
lines.pop_front();
for (auto lniter = lines.begin(); lniter != lines.end(); ++lniter) {
// TODO: See if any of these fields are useful to us...
}
if (path == "/status") {
DS::String json = "{'online':true";
DS::String welcome = DS::Settings::WelcomeMsg();
welcome.replace("\"", "\\\"");
json += DS::String::Format(",'welcome':\"%s\"", welcome.c_str());
json += "}\r\n";
// TODO: Add more status fields (players/ages, etc)
SEND_RAW(client, "HTTP/1.1 200 OK\r\n");
SEND_RAW(client, "Server: Dirtsand\r\n");
SEND_RAW(client, "Connection: close\r\n");
SEND_RAW(client, "Accept-Ranges: bytes\r\n");
DS::String lengthParam = DS::String::Format("Content-Length: %u\r\n", json.length());
DS::SendBuffer(client, lengthParam.c_str(), lengthParam.length());
SEND_RAW(client, "Content-Type: application/json\r\n");
//.........这里部分代码省略.........