7#include <ucs/type/status.h>
9#include <ucp/api/ucp.h>
13constexpr size_t kErrorStringBufferSize = 1024;
15static inline void throw_with(
const char *message) {
16 throw std::runtime_error(message);
19template <
class... Args>
20static inline void throw_with(
const char *format, Args... args) {
21 char buffer[kErrorStringBufferSize];
22 ::snprintf(buffer,
sizeof(buffer), format, args...);
23 throw std::runtime_error(buffer);
26static inline void check_ucs_status(ucs_status_t status,
const char *message) {
27 if (status == UCS_OK) [[likely]] {
30 if (status == UCS_INPROGRESS) [[likely]] {
34 throw_with(
"%s: %s (status=%d)", message, ::ucs_status_string(status),
38static inline void check_rc(
int rc,
const char *message) {
39 if (rc != 0) [[unlikely]] {
40 throw_with(
"%s: %s (rc=%d)", message, ::strerror(rc), rc);
44static inline void check_ptr(
void *ptr,
const char *message) {
45 if (ptr ==
nullptr) [[unlikely]] {
46 throw_with(
"%s: %s (errno=%d)", message, ::strerror(errno), errno);
50static inline void check_errno(
int rc,
const char *message) {
51 if (rc < 0) [[unlikely]] {
52 throw_with(
"%s: %s (errno=%d)", message, ::strerror(errno), errno);