std::string shorten(folly::StringPiece s, size_t maxLength) { if (s.size() <= maxLength || s.size() <= 3) { return s.str(); } return s.subpiece(0, maxLength - 3).str() + "..."; }
void MockMc::set(folly::StringPiece key, Item item) { citems_.erase(key.str()); citems_.insert(std::make_pair(key.str(), CacheItem(std::move(item)))); }
void SessionTestHarness::inputPacket(folly::StringPiece p) { savedInputs_.push_back(p.str()); flushSavedInputs(); }
size_t operator()(folly::StringPiece key) const { return std::stoi(key.str()) % n_; }
RoutingPrefix::RoutingPrefix(folly::StringPiece prefix) : prefix_(prefix.str()) { initFromPrefix(); }
/** Adds an asynchronous request to the event log. */ void asynclog_delete(proxy_t* proxy, const AccessPoint& ap, folly::StringPiece key, folly::StringPiece poolName) { dynamic json = {}; const auto& host = ap.getHost(); const auto& port = proxy->router().opts().asynclog_port_override == 0 ? ap.getPort() : proxy->router().opts().asynclog_port_override; if (proxy->router().opts().use_asynclog_version2) { json = dynamic::object; json["f"] = proxy->router().opts().flavor_name; json["h"] = folly::sformat("[{}]:{}", host, port); json["p"] = poolName.str(); json["k"] = key.str(); } else { /* ["host", port, escaped_command] */ json.push_back(host); json.push_back(port); json.push_back(folly::sformat("delete {}\r\n", key)); } auto fd = asynclog_open(proxy); if (!fd) { MC_LOG_FAILURE(proxy->router().opts(), memcache::failure::Category::kSystemError, "asynclog_open() failed (key {}, pool {})", key, poolName); return; } // ["AS1.0", 1289416829.836, "C", ["10.0.0.1", 11302, "delete foo\r\n"]] // OR ["AS2.0", 1289416829.836, "C", {"f":"flavor","h":"[10.0.0.1]:11302", // "p":"pool_name","k":"foo\r\n"}] dynamic jsonOut = {}; if (proxy->router().opts().use_asynclog_version2) { jsonOut.push_back(ASYNCLOG_MAGIC2); } else { jsonOut.push_back(ASYNCLOG_MAGIC); } struct timeval timestamp; CHECK(gettimeofday(×tamp, nullptr) == 0); auto timestamp_ms = facebook::memcache::to<std::chrono::milliseconds>(timestamp).count(); jsonOut.push_back(1e-3 * timestamp_ms); jsonOut.push_back(std::string("C")); jsonOut.push_back(json); auto jstr = folly::toJson(jsonOut) + "\n"; ssize_t size = folly::writeFull(fd->fd(), jstr.data(), jstr.size()); if (size == -1 || size_t(size) < jstr.size()) { MC_LOG_FAILURE(proxy->router().opts(), memcache::failure::Category::kSystemError, "Error fully writing asynclog request (key {}, pool {})", key, poolName); } }
PcapFile::PcapFile(folly::StringPiece path, bool overwriteExisting) : file_(path.str().c_str(), openFlags(overwriteExisting), 0644) { }