bool socket_write_string(int fd, const std::string &str) { if (!socket_write_int32(fd, str.size())) { return false; } if (socket_write(fd, str.data(), str.size()) == (ssize_t) str.size()) { return true; } return false; }
bool socket_write_bytes(int fd, const uint8_t *data, size_t len) { if (!socket_write_int32(fd, len)) { return false; } if (socket_write(fd, data, len) == (ssize_t) len) { return true; } return false; }
bool socket_write_string_array(int fd, const std::vector<std::string> &list) { if (!socket_write_int32(fd, list.size())) { return false; } for (const std::string &str : list) { if (!socket_write_string(fd, str)) { return false; } } return true; }
oc::result<void> socket_write_string_array(int fd, const std::vector<std::string> &list) { if (list.size() > INT32_MAX) { return std::errc::invalid_argument; } OUTCOME_TRYV(socket_write_int32(fd, static_cast<int32_t>(list.size()))); for (const std::string &str : list) { OUTCOME_TRYV(socket_write_string(fd, str)); } return oc::success(); }
oc::result<void> socket_write_string(int fd, const std::string &str) { if (str.size() > INT32_MAX) { return std::errc::invalid_argument; } OUTCOME_TRYV(socket_write_int32(fd, static_cast<int32_t>(str.size()))); OUTCOME_TRY(n, socket_write(fd, str.data(), str.size())); if (n != str.size()) { return std::errc::io_error; } return oc::success(); }
oc::result<void> socket_write_bytes(int fd, const void *data, size_t len) { if (len > INT32_MAX) { return std::errc::invalid_argument; } OUTCOME_TRYV(socket_write_int32(fd, static_cast<int32_t>(len))); OUTCOME_TRY(n, socket_write(fd, data, len)); if (n != len) { return std::errc::io_error; } return oc::success(); }