Sponge
CS144's user-space TCP library
Public Member Functions | Public Attributes | List of all members
FileDescriptor::FDWrapper Class Reference

A handle on a kernel file descriptor. More...

Public Member Functions

 FDWrapper (const int fd)
 Construct from a file descriptor number returned by the kernel. More...
 
 ~FDWrapper ()
 Closes the file descriptor upon destruction. More...
 
void close ()
 Calls close(2) on FDWrapper::_fd. More...
 

An FDWrapper cannot be copied or moved

 FDWrapper (const FDWrapper &other)=delete
 
FDWrapperoperator= (const FDWrapper &other)=delete
 
 FDWrapper (FDWrapper &&other)=delete
 
FDWrapperoperator= (FDWrapper &&other)=delete
 

Public Attributes

bool _closed = false
 Flag indicating whether FDWrapper::_fd has been closed. More...
 
bool _eof = false
 Flag indicating whether FDWrapper::_fd is at EOF. More...
 
int _fd
 The file descriptor number returned by the kernel. More...
 
unsigned _read_count = 0
 The number of times FDWrapper::_fd has been read. More...
 
unsigned _write_count = 0
 The numberof times FDWrapper::_fd has been written. More...
 

Detailed Description

A handle on a kernel file descriptor.

FileDescriptor objects contain a std::shared_ptr to a FDWrapper.

Definition at line 15 of file file_descriptor.hh.

Constructor & Destructor Documentation

◆ FDWrapper() [1/3]

FileDescriptor::FDWrapper::FDWrapper ( const int  fd)
explicit

Construct from a file descriptor number returned by the kernel.

Parameters
[in]fdis the file descriptor number returned by open(2) or similar

Definition at line 15 of file file_descriptor.cc.

◆ ~FDWrapper()

FileDescriptor::FDWrapper::~FDWrapper ( )

Closes the file descriptor upon destruction.

Definition at line 26 of file file_descriptor.cc.

◆ FDWrapper() [2/3]

FileDescriptor::FDWrapper::FDWrapper ( const FDWrapper other)
delete

◆ FDWrapper() [3/3]

FileDescriptor::FDWrapper::FDWrapper ( FDWrapper &&  other)
delete

Member Function Documentation

◆ close()

void FileDescriptor::FDWrapper::close ( )

Calls close(2) on FDWrapper::_fd.

Definition at line 21 of file file_descriptor.cc.

◆ operator=() [1/2]

FDWrapper& FileDescriptor::FDWrapper::operator= ( const FDWrapper other)
delete

◆ operator=() [2/2]

FDWrapper& FileDescriptor::FDWrapper::operator= ( FDWrapper &&  other)
delete

Member Data Documentation

◆ _closed

bool FileDescriptor::FDWrapper::_closed = false

Flag indicating whether FDWrapper::_fd has been closed.

Definition at line 19 of file file_descriptor.hh.

◆ _eof

bool FileDescriptor::FDWrapper::_eof = false

Flag indicating whether FDWrapper::_fd is at EOF.

Definition at line 18 of file file_descriptor.hh.

◆ _fd

int FileDescriptor::FDWrapper::_fd

The file descriptor number returned by the kernel.

Definition at line 17 of file file_descriptor.hh.

◆ _read_count

unsigned FileDescriptor::FDWrapper::_read_count = 0

The number of times FDWrapper::_fd has been read.

Definition at line 20 of file file_descriptor.hh.

◆ _write_count

unsigned FileDescriptor::FDWrapper::_write_count = 0

The numberof times FDWrapper::_fd has been written.

Definition at line 21 of file file_descriptor.hh.


The documentation for this class was generated from the following files: