From 98d3e888728842e419b4851c22adf57e589ba56a Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Sun, 26 Apr 2020 16:22:56 +0200 Subject: [PATCH] added close() to socketstream --- libscio.hpp | 2 ++ socketstream.cpp | 5 +++++ 2 files changed, 7 insertions(+) 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); } }