m-renaud/posix-lib

File Descriptor - Auto-close Doesn't Properly Handle Errors

Opened this issue · 1 comments

If auto_close is set for the file descriptor, ::close() is invoked in the destructor but not all errors can be properly handled.

EBADF

Occurs when fd isn't a valid file descriptor.

Possible solution is to ignore this error as the file descriptor may have already been closed. Nothing should be wrong with redundant closing.

EIO

An I/O error has occurred.

Not sure exactly how you would go about handling this error.

Since it is poor design to write destructors that throw, the auto close shall be removed from file_descriptor. In order to close a file_descriptor, the close() member function must be invoked so that proper error handling can be done.

Note: This change was made in the exception branch for now and will eventually be merged back into master when a fully robust implementation is complete.