From 44d4e29922f151d2082a7fed782ffd2ee1191413 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Sat, 25 Apr 2020 18:10:38 +0200 Subject: [PATCH] added is_open and close methods on fdstreams --- fdstream.cpp | 12 ++++++++++++ libscio.hpp | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/fdstream.cpp b/fdstream.cpp index b977e34..ae1c30b 100644 --- a/fdstream.cpp +++ b/fdstream.cpp @@ -10,18 +10,30 @@ #include sc::io::fdostream::~fdostream() { + close(); +} + +void sc::io::fdostream::close() { if (_outbuf.fd() != -1) { ::close(_outbuf.fd()); } } sc::io::fdistream::~fdistream() { + close(); +} + +void sc::io::fdistream::close() { if (_inbuf.fd() != -1) { ::close(_inbuf.fd()); } } sc::io::fdstream::~fdstream() { + close(); +} + +void sc::io::fdstream::close() { if (_iobuf.fd() != -1) { ::close(_iobuf.fd()); } diff --git a/libscio.hpp b/libscio.hpp index 051e0ce..05ed456 100644 --- a/libscio.hpp +++ b/libscio.hpp @@ -61,6 +61,9 @@ namespace sc { int fd() const { return _outbuf.fd(); } void fd(int fd) { _outbuf.fd(fd); } + bool is_open() const { return _outbuf.fd() != -1; } + void close(); + protected: fdiobuf _outbuf; }; @@ -75,6 +78,9 @@ namespace sc { int fd() const { return _inbuf.fd(); } void fd(int fd) { _inbuf.fd(fd); } + bool is_open() const { return _inbuf.fd() != -1; } + void close(); + protected: fdiobuf _inbuf; }; @@ -89,6 +95,9 @@ namespace sc { int fd() const { return _iobuf.fd(); } void fd(int fd) { _iobuf.fd(fd); } + bool is_open() const { return _iobuf.fd() != -1; } + void close(); + protected: fdiobuf _iobuf {-1}; };