fd: add reset and release methods
This commit is contained in:
parent
ac685cfdd2
commit
fe979fc2a9
36
posix/fd.cpp
36
posix/fd.cpp
@ -94,13 +94,43 @@ fd::stat (void) const
|
||||
ssize_t
|
||||
fd::read (void *buffer, size_t count)
|
||||
{
|
||||
return error::try_value (
|
||||
::read (m_fd, buffer, count)
|
||||
);
|
||||
error::try_value (::close (m_fd));
|
||||
m_fd = -1;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
fd::reset (void)
|
||||
{
|
||||
if (m_fd >= 0) {
|
||||
close ();
|
||||
m_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
fd::reset (int rhs)
|
||||
{
|
||||
if (m_fd >= 0)
|
||||
close ();
|
||||
m_fd = rhs;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int
|
||||
fd::release (void)
|
||||
{
|
||||
int tmp = m_fd;
|
||||
m_fd = -1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
ssize_t
|
||||
fd::read (util::view<char *> dst)
|
||||
{
|
||||
|
@ -53,6 +53,13 @@ namespace util::posix {
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
struct ::stat stat (void) const;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void close (void);
|
||||
void reset (int);
|
||||
void reset (void);
|
||||
int release (void);
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
[[gnu::warn_unused_result]] ssize_t read (void *buf, size_t count);
|
||||
[[gnu::warn_unused_result]] ssize_t read (util::view<char*>);
|
||||
|
Loading…
Reference in New Issue
Block a user