io/FileDescriptor: add Read()/Write() overloads with std::span
This commit is contained in:
parent
5fbe5951ab
commit
cad35a83fb
|
@ -64,8 +64,7 @@ try {
|
|||
static_assert(sizeof(buffer) >= sizeof(struct inotify_event) + NAME_MAX + 1,
|
||||
"inotify buffer too small");
|
||||
|
||||
ssize_t nbytes = event.GetFileDescriptor().Read(buffer.data(),
|
||||
buffer.size());
|
||||
ssize_t nbytes = event.GetFileDescriptor().Read(buffer);
|
||||
if (nbytes <= 0) [[unlikely]] {
|
||||
if (nbytes == 0)
|
||||
throw std::runtime_error{"EOF from inotify"};
|
||||
|
|
|
@ -217,6 +217,10 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
ssize_t Read(std::span<std::byte> dest) const noexcept {
|
||||
return ::read(fd, dest.data(), dest.size());
|
||||
}
|
||||
|
||||
ssize_t Read(void *buffer, std::size_t length) const noexcept {
|
||||
return ::read(fd, buffer, length);
|
||||
}
|
||||
|
@ -227,6 +231,10 @@ public:
|
|||
*/
|
||||
void FullRead(std::span<std::byte> dest) const;
|
||||
|
||||
ssize_t Write(std::span<const std::byte> src) const noexcept {
|
||||
return ::write(fd, src.data(), src.size());
|
||||
}
|
||||
|
||||
ssize_t Write(const void *buffer, std::size_t length) const noexcept {
|
||||
return ::write(fd, buffer, length);
|
||||
}
|
||||
|
|
|
@ -671,7 +671,7 @@ OssOutput::Play(std::span<const std::byte> src)
|
|||
return src.size();
|
||||
|
||||
while (true) {
|
||||
const ssize_t ret = fd.Write(e.data(), e.size());
|
||||
const ssize_t ret = fd.Write(e);
|
||||
if (ret > 0)
|
||||
return pcm_export->CalcInputSize(ret);
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ SolarisOutput::Close() noexcept
|
|||
std::size_t
|
||||
SolarisOutput::Play(std::span<const std::byte> src)
|
||||
{
|
||||
ssize_t nbytes = fd.Write(src.data(), src.size());
|
||||
ssize_t nbytes = fd.Write(src);
|
||||
if (nbytes <= 0)
|
||||
throw MakeErrno("Write failed");
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ EventFD::Read() noexcept
|
|||
assert(fd.IsDefined());
|
||||
|
||||
eventfd_t value;
|
||||
return fd.Read(&value, sizeof(value)) == (ssize_t)sizeof(value);
|
||||
return fd.Read(std::as_writable_bytes(std::span{&value, 1})) == (ssize_t)sizeof(value);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -99,7 +99,7 @@ RunConvert(PcmConvert &convert, size_t in_frame_size,
|
|||
const auto dest = buffer.Write();
|
||||
assert(!dest.empty());
|
||||
|
||||
ssize_t nbytes = in_fd.Read(dest.data(), dest.size());
|
||||
ssize_t nbytes = in_fd.Read(dest);
|
||||
if (nbytes <= 0)
|
||||
break;
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ RunOutput(AudioOutput &ao, AudioFormat audio_format,
|
|||
const auto dest = buffer.Write();
|
||||
assert(!dest.empty());
|
||||
|
||||
ssize_t nbytes = in_fd.Read(dest.data(), dest.size());
|
||||
ssize_t nbytes = in_fd.Read(dest);
|
||||
if (nbytes <= 0)
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue