MCPcopy Create free account
hub / github.com/PABannier/bark.cpp / write_format

Method write_format

examples/server/httplib.h:1752–1773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1750
1751template <typename... Args>
1752inline ssize_t Stream::write_format(const char *fmt, const Args &...args) {
1753 const auto bufsiz = 2048;
1754 std::array<char, bufsiz> buf{};
1755
1756 auto sn = snprintf(buf.data(), buf.size() - 1, fmt, args...);
1757 if (sn <= 0) { return sn; }
1758
1759 auto n = static_cast<size_t>(sn);
1760
1761 if (n >= buf.size() - 1) {
1762 std::vector<char> glowable_buf(buf.size());
1763
1764 while (n >= glowable_buf.size() - 1) {
1765 glowable_buf.resize(glowable_buf.size() * 2);
1766 n = static_cast<size_t>(
1767 snprintf(&glowable_buf[0], glowable_buf.size() - 1, fmt, args...));
1768 }
1769 return write(&glowable_buf[0], n);
1770 } else {
1771 return write(buf.data(), n);
1772 }
1773}
1774
1775inline void default_socket_options(socket_t sock) {
1776 int yes = 1;

Callers 4

write_headersFunction · 0.80
write_response_coreMethod · 0.80
process_requestMethod · 0.80
write_requestMethod · 0.80

Calls 2

dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected