|
Sponge
CS144's user-space TCP library
|
Go to the documentation of this file. 1 #ifndef SPONGE_LIBSPONGE_FILE_DESCRIPTOR_HH
2 #define SPONGE_LIBSPONGE_FILE_DESCRIPTOR_HH
117 #endif // SPONGE_LIBSPONGE_FILE_DESCRIPTOR_HH
bool eof() const
EOF flag state.
size_t write(const char *str, const bool write_all=true)
Write a string, possibly blocking until all is written.
void close()
Calls close(2) on FDWrapper::_fd.
FDWrapper(const int fd)
Construct from a file descriptor number returned by the kernel.
void close()
Close the underlying file descriptor.
int fd_num() const
underlying descriptor number
A non-owning temporary view (similar to std::string_view) of a discontiguous string.
A reference-counted handle to a file descriptor.
bool _closed
Flag indicating whether FDWrapper::_fd has been closed.
unsigned int read_count() const
number of reads
std::string read(const size_t limit=std::numeric_limits< size_t >::max())
Read up to limit bytes.
unsigned _write_count
The numberof times FDWrapper::_fd has been written.
bool _eof
Flag indicating whether FDWrapper::_fd is at EOF.
FDWrapper & operator=(const FDWrapper &other)=delete
FileDescriptor & operator=(const FileDescriptor &other)=delete
copy assignment is forbidden
void set_blocking(const bool blocking_state)
Set blocking(true) or non-blocking(false)
unsigned int write_count() const
number of writes
A handle on a kernel file descriptor.
size_t write(const std::string &str, const bool write_all=true)
Write a string, possibly blocking until all is written.
FileDescriptor(std::shared_ptr< FDWrapper > other_shared_ptr)
Private constructor used by duplicate()
~FDWrapper()
Closes the file descriptor upon destruction.
unsigned _read_count
The number of times FDWrapper::_fd has been read.
int _fd
The file descriptor number returned by the kernel.
std::shared_ptr< FDWrapper > _internal_fd
A reference-counted handle to a shared FDWrapper.
~FileDescriptor()=default
Free the std::shared_ptr; the FDWrapper destructor calls close() when the refcount goes to zero.
FileDescriptor duplicate() const
Copy a FileDescriptor explicitly, increasing the FDWrapper refcount.
bool closed() const
closed flag state