added is_open and close methods on fdstreams

This commit is contained in:
Bob Polis 2020-04-25 18:10:38 +02:00
parent 3c26c0616e
commit 44d4e29922
2 changed files with 21 additions and 0 deletions

View File

@ -10,18 +10,30 @@
#include <unistd.h> #include <unistd.h>
sc::io::fdostream::~fdostream() { sc::io::fdostream::~fdostream() {
close();
}
void sc::io::fdostream::close() {
if (_outbuf.fd() != -1) { if (_outbuf.fd() != -1) {
::close(_outbuf.fd()); ::close(_outbuf.fd());
} }
} }
sc::io::fdistream::~fdistream() { sc::io::fdistream::~fdistream() {
close();
}
void sc::io::fdistream::close() {
if (_inbuf.fd() != -1) { if (_inbuf.fd() != -1) {
::close(_inbuf.fd()); ::close(_inbuf.fd());
} }
} }
sc::io::fdstream::~fdstream() { sc::io::fdstream::~fdstream() {
close();
}
void sc::io::fdstream::close() {
if (_iobuf.fd() != -1) { if (_iobuf.fd() != -1) {
::close(_iobuf.fd()); ::close(_iobuf.fd());
} }

View File

@ -61,6 +61,9 @@ namespace sc {
int fd() const { return _outbuf.fd(); } int fd() const { return _outbuf.fd(); }
void fd(int fd) { _outbuf.fd(fd); } void fd(int fd) { _outbuf.fd(fd); }
bool is_open() const { return _outbuf.fd() != -1; }
void close();
protected: protected:
fdiobuf _outbuf; fdiobuf _outbuf;
}; };
@ -75,6 +78,9 @@ namespace sc {
int fd() const { return _inbuf.fd(); } int fd() const { return _inbuf.fd(); }
void fd(int fd) { _inbuf.fd(fd); } void fd(int fd) { _inbuf.fd(fd); }
bool is_open() const { return _inbuf.fd() != -1; }
void close();
protected: protected:
fdiobuf _inbuf; fdiobuf _inbuf;
}; };
@ -89,6 +95,9 @@ namespace sc {
int fd() const { return _iobuf.fd(); } int fd() const { return _iobuf.fd(); }
void fd(int fd) { _iobuf.fd(fd); } void fd(int fd) { _iobuf.fd(fd); }
bool is_open() const { return _iobuf.fd() != -1; }
void close();
protected: protected:
fdiobuf _iobuf {-1}; fdiobuf _iobuf {-1};
}; };