2019-07-07 02:05:30 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2019-07-07 02:05:30 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
|
|
|
|
#if TD_PORT_POSIX
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace td {
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
#if TD_PORT_POSIX
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
using IoSlice = struct iovec;
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
inline IoSlice as_io_slice(Slice slice) {
|
|
|
|
IoSlice res;
|
|
|
|
res.iov_len = slice.size();
|
|
|
|
res.iov_base = const_cast<char *>(slice.data());
|
|
|
|
return res;
|
|
|
|
}
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2021-04-03 23:40:37 +02:00
|
|
|
inline Slice as_slice(const IoSlice &io_slice) {
|
2019-07-21 20:07:07 +02:00
|
|
|
return Slice(static_cast<const char *>(io_slice.iov_base), io_slice.iov_len);
|
2019-07-07 02:05:30 +02:00
|
|
|
}
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
#else
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
using IoSlice = Slice;
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
inline IoSlice as_io_slice(Slice slice) {
|
|
|
|
return slice;
|
|
|
|
}
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
#endif
|
2019-07-21 20:07:07 +02:00
|
|
|
|
2019-07-07 02:05:30 +02:00
|
|
|
} // namespace td
|