io/FileDescriptor, net/SocketDescriptor: make lots of methods "const"
Only the file descriptor value itself is const, but the file itself may be readable/writable.
This commit is contained in:
committed by
Max Kellermann
parent
69596106d3
commit
bbc82a9892
@@ -185,7 +185,7 @@ FileDescriptor::CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept
|
||||
#ifdef _WIN32
|
||||
|
||||
void
|
||||
FileDescriptor::SetBinaryMode() noexcept
|
||||
FileDescriptor::SetBinaryMode() const noexcept
|
||||
{
|
||||
_setmode(fd, _O_BINARY);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ FileDescriptor::CreatePipeNonBlock(FileDescriptor &r,
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::SetNonBlocking() noexcept
|
||||
FileDescriptor::SetNonBlocking() const noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -218,7 +218,7 @@ FileDescriptor::SetNonBlocking() noexcept
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::SetBlocking() noexcept
|
||||
FileDescriptor::SetBlocking() const noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -227,7 +227,7 @@ FileDescriptor::SetBlocking() noexcept
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::EnableCloseOnExec() noexcept
|
||||
FileDescriptor::EnableCloseOnExec() const noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -236,7 +236,7 @@ FileDescriptor::EnableCloseOnExec() noexcept
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::DisableCloseOnExec() noexcept
|
||||
FileDescriptor::DisableCloseOnExec() const noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -251,7 +251,7 @@ FileDescriptor::Duplicate() const noexcept
|
||||
}
|
||||
|
||||
bool
|
||||
FileDescriptor::CheckDuplicate(FileDescriptor new_fd) noexcept
|
||||
FileDescriptor::CheckDuplicate(FileDescriptor new_fd) const noexcept
|
||||
{
|
||||
if (*this == new_fd) {
|
||||
DisableCloseOnExec();
|
||||
@@ -285,7 +285,7 @@ FileDescriptor::CreateSignalFD(const sigset_t *mask) noexcept
|
||||
#endif
|
||||
|
||||
bool
|
||||
FileDescriptor::Rewind() noexcept
|
||||
FileDescriptor::Rewind() const noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -302,7 +302,7 @@ FileDescriptor::GetSize() const noexcept
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::FullRead(void *_buffer, std::size_t length)
|
||||
FileDescriptor::FullRead(void *_buffer, std::size_t length) const
|
||||
{
|
||||
auto buffer = (std::byte *)_buffer;
|
||||
|
||||
@@ -320,7 +320,7 @@ FileDescriptor::FullRead(void *_buffer, std::size_t length)
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::FullWrite(const void *_buffer, std::size_t length)
|
||||
FileDescriptor::FullWrite(const void *_buffer, std::size_t length) const
|
||||
{
|
||||
auto buffer = (const std::byte *)_buffer;
|
||||
|
||||
|
||||
+18
-17
@@ -151,36 +151,36 @@ public:
|
||||
static bool CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept;
|
||||
|
||||
#ifdef _WIN32
|
||||
void EnableCloseOnExec() noexcept {}
|
||||
void DisableCloseOnExec() noexcept {}
|
||||
void SetBinaryMode() noexcept;
|
||||
void EnableCloseOnExec() const noexcept {}
|
||||
void DisableCloseOnExec() const noexcept {}
|
||||
void SetBinaryMode() const noexcept;
|
||||
#else
|
||||
static bool CreatePipeNonBlock(FileDescriptor &r,
|
||||
FileDescriptor &w) noexcept;
|
||||
|
||||
void SetBinaryMode() noexcept {}
|
||||
void SetBinaryMode() const noexcept {}
|
||||
|
||||
/**
|
||||
* Enable non-blocking mode on this file descriptor.
|
||||
*/
|
||||
void SetNonBlocking() noexcept;
|
||||
void SetNonBlocking() const noexcept;
|
||||
|
||||
/**
|
||||
* Enable blocking mode on this file descriptor.
|
||||
*/
|
||||
void SetBlocking() noexcept;
|
||||
void SetBlocking() const noexcept;
|
||||
|
||||
/**
|
||||
* Auto-close this file descriptor when a new program is
|
||||
* executed.
|
||||
*/
|
||||
void EnableCloseOnExec() noexcept;
|
||||
void EnableCloseOnExec() const noexcept;
|
||||
|
||||
/**
|
||||
* Do not auto-close this file descriptor when a new program
|
||||
* is executed.
|
||||
*/
|
||||
void DisableCloseOnExec() noexcept;
|
||||
void DisableCloseOnExec() const noexcept;
|
||||
|
||||
/**
|
||||
* Duplicate this file descriptor.
|
||||
@@ -203,7 +203,7 @@ public:
|
||||
* this method to inject file descriptors into a new child
|
||||
* process, to be used by a newly executed program.
|
||||
*/
|
||||
bool CheckDuplicate(FileDescriptor new_fd) noexcept;
|
||||
bool CheckDuplicate(FileDescriptor new_fd) const noexcept;
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
@@ -223,13 +223,13 @@ public:
|
||||
/**
|
||||
* Rewind the pointer to the beginning of the file.
|
||||
*/
|
||||
bool Rewind() noexcept;
|
||||
bool Rewind() const noexcept;
|
||||
|
||||
off_t Seek(off_t offset) noexcept {
|
||||
off_t Seek(off_t offset) const noexcept {
|
||||
return lseek(Get(), offset, SEEK_SET);
|
||||
}
|
||||
|
||||
off_t Skip(off_t offset) noexcept {
|
||||
off_t Skip(off_t offset) const noexcept {
|
||||
return lseek(Get(), offset, SEEK_CUR);
|
||||
}
|
||||
|
||||
@@ -245,12 +245,13 @@ public:
|
||||
off_t GetSize() const noexcept;
|
||||
|
||||
#ifndef _WIN32
|
||||
ssize_t ReadAt(off_t offset, void *buffer, std::size_t length) noexcept {
|
||||
ssize_t ReadAt(off_t offset,
|
||||
void *buffer, std::size_t length) const noexcept {
|
||||
return ::pread(fd, buffer, length, offset);
|
||||
}
|
||||
#endif
|
||||
|
||||
ssize_t Read(void *buffer, std::size_t length) noexcept {
|
||||
ssize_t Read(void *buffer, std::size_t length) const noexcept {
|
||||
return ::read(fd, buffer, length);
|
||||
}
|
||||
|
||||
@@ -258,9 +259,9 @@ public:
|
||||
* Read until all of the given buffer has been filled. Throws
|
||||
* on error.
|
||||
*/
|
||||
void FullRead(void *buffer, std::size_t length);
|
||||
void FullRead(void *buffer, std::size_t length) const;
|
||||
|
||||
ssize_t Write(const void *buffer, std::size_t length) noexcept {
|
||||
ssize_t Write(const void *buffer, std::size_t length) const noexcept {
|
||||
return ::write(fd, buffer, length);
|
||||
}
|
||||
|
||||
@@ -268,7 +269,7 @@ public:
|
||||
* Write until all of the given buffer has been written.
|
||||
* Throws on error.
|
||||
*/
|
||||
void FullWrite(const void *buffer, std::size_t length);
|
||||
void FullWrite(const void *buffer, std::size_t length) const;
|
||||
|
||||
#ifndef _WIN32
|
||||
int Poll(short events, int timeout) const noexcept;
|
||||
|
||||
Reference in New Issue
Block a user