mirror of
https://github.com/XTXMarkets/ternfs.git
synced 2025-12-30 23:39:46 -06:00
The idea is to drain the socket and do a single RocksDB WAL write/fsync for all the write requests we have found. The read requests are immediately executed. The reasoning here is that currently write requests are _a lot_ slower than the read requests because fsyncing takes ~500us on fsf1. In the future this might change. Since we're at it, we also use batch UDP syscalls in the CDC. Fixes #119.
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#include "Common.hpp"
|
|
|
|
#include <arpa/inet.h>
|
|
#include <netinet/in.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <iomanip>
|
|
|
|
std::ostream& operator<<(std::ostream& out, const struct sockaddr_in& addr) {
|
|
char buf[INET_ADDRSTRLEN];
|
|
inet_ntop(AF_INET, &addr.sin_addr, buf, sizeof(buf));
|
|
out << buf << ":" << ntohs(addr.sin_port);
|
|
return out;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& out, const struct in_addr& addr) {
|
|
char buf[INET_ADDRSTRLEN];
|
|
inet_ntop(AF_INET, &addr, buf, sizeof(buf));
|
|
out << buf;
|
|
return out;
|
|
}
|
|
|
|
std::ostream& goLangBytesFmt(std::ostream& out, const char* str, size_t len) {
|
|
out << "[";
|
|
const uint8_t* data = (const uint8_t*)str;
|
|
for (int i = 0; i < len; i++) {
|
|
if (i > 0) {
|
|
out << " ";
|
|
}
|
|
out << (int)data[i];
|
|
}
|
|
out << "]";
|
|
return out;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& out, const GoLangBytesFmt& bytes) {
|
|
return goLangBytesFmt(out, bytes.str, bytes.len);
|
|
}
|
|
|
|
std::ostream& goLangQuotedStringFmt(std::ostream& out, const char* data, size_t len) {
|
|
out << "\"";
|
|
for (int i = 0; i < len; i++) {
|
|
uint8_t ch = static_cast<uint8_t>(data[i]);
|
|
if (isprint(ch)) {
|
|
out << ch;
|
|
} else if (ch == 0) {
|
|
out << "\\0";
|
|
} else {
|
|
const char cfill = out.fill();
|
|
out << std::hex << std::setfill('0');
|
|
out << "\\x" << std::setw(2) << (int)ch;
|
|
out << std::setfill(cfill) << std::dec;
|
|
}
|
|
}
|
|
out << "\"";
|
|
return out;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& out, const GoLangQuotedStringFmt& bytes) {
|
|
return goLangQuotedStringFmt(out, bytes.str, bytes.len);
|
|
} |