diff --git a/libscio.hpp b/libscio.hpp index 8a98aa2..0d7ecb4 100644 --- a/libscio.hpp +++ b/libscio.hpp @@ -149,6 +149,8 @@ namespace sc { // cleanup: socketstream is RAII class for open socket virtual ~socketstream(); + bool is_open() { return _iobuf.fd() != -1; } + void close(); // server void make_server(const socket_address& sa); diff --git a/socketstream.cpp b/socketstream.cpp index 54a32e1..597f5a2 100644 --- a/socketstream.cpp +++ b/socketstream.cpp @@ -53,8 +53,13 @@ socketstream& socketstream::operator=(socketstream&& other) { } socketstream::~socketstream() { + close(); +} + +void socketstream::close() { if (_iobuf.fd() != -1) { ::close(_iobuf.fd()); + _iobuf.fd(-1); } }